mirror of
https://github.com/ml-explore/mlx.git
synced 2025-08-06 11:36:48 +08:00
Read/write files in binary mode (#1698)
This commit is contained in:
parent
50f3535693
commit
635117c5d4
@ -15,6 +15,14 @@
|
|||||||
|
|
||||||
#include "mlx/io/threadpool.h"
|
#include "mlx/io/threadpool.h"
|
||||||
|
|
||||||
|
// Strictly we need to operate on files in binary mode (to avoid \r getting
|
||||||
|
// automatically inserted), but every modern system except for Windows no
|
||||||
|
// longer differentiates between binary and text files and for them define
|
||||||
|
// the flag as no-op.
|
||||||
|
#ifndef O_BINARY
|
||||||
|
#define O_BINARY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mlx::core {
|
namespace mlx::core {
|
||||||
|
|
||||||
namespace io {
|
namespace io {
|
||||||
@ -51,7 +59,8 @@ class Writer {
|
|||||||
class ParallelFileReader : public Reader {
|
class ParallelFileReader : public Reader {
|
||||||
public:
|
public:
|
||||||
explicit ParallelFileReader(std::string file_path)
|
explicit ParallelFileReader(std::string file_path)
|
||||||
: fd_(open(file_path.c_str(), O_RDONLY)), label_(std::move(file_path)) {}
|
: fd_(open(file_path.c_str(), O_RDONLY | O_BINARY)),
|
||||||
|
label_(std::move(file_path)) {}
|
||||||
|
|
||||||
~ParallelFileReader() override {
|
~ParallelFileReader() override {
|
||||||
close(fd_);
|
close(fd_);
|
||||||
@ -93,7 +102,10 @@ class ParallelFileReader : public Reader {
|
|||||||
class FileWriter : public Writer {
|
class FileWriter : public Writer {
|
||||||
public:
|
public:
|
||||||
explicit FileWriter(std::string file_path)
|
explicit FileWriter(std::string file_path)
|
||||||
: fd_(open(file_path.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644)),
|
: fd_(open(
|
||||||
|
file_path.c_str(),
|
||||||
|
O_CREAT | O_WRONLY | O_TRUNC | O_BINARY,
|
||||||
|
0644)),
|
||||||
label_(std::move(file_path)) {}
|
label_(std::move(file_path)) {}
|
||||||
|
|
||||||
~FileWriter() override {
|
~FileWriter() override {
|
||||||
|
Loading…
Reference in New Issue
Block a user