Skip to content

Commit f4e3b6a

Browse files
xuepanchenwesm
authored andcommitted
Add static constructor for FileOutputStream returning pointer to base OutputStream
1 parent 9fefc23 commit f4e3b6a

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

cpp/src/arrow/io/file.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,17 @@ FileOutputStream::~FileOutputStream() {
554554
DCHECK(impl_->Close().ok());
555555
}
556556

557+
Status FileOutputStream::Open(const std::string& path,
558+
std::shared_ptr<OutputStream>* file) {
559+
return Open(path, false, file);
560+
}
561+
562+
Status FileOutputStream::Open(const std::string& path, bool append,
563+
std::shared_ptr<OutputStream>* out) {
564+
*out = std::shared_ptr<FileOutputStream>(new FileOutputStream());
565+
return std::static_pointer_cast<FileOutputStream>(*out)->impl_->Open(path, append);
566+
}
567+
557568
Status FileOutputStream::Open(const std::string& path,
558569
std::shared_ptr<FileOutputStream>* file) {
559570
return Open(path, false, file);

cpp/src/arrow/io/file.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ class ARROW_EXPORT FileOutputStream : public OutputStream {
3939
public:
4040
~FileOutputStream() override;
4141

42+
/// \brief Open a local file for writing, truncating any existing file
43+
/// \param[in] path with UTF8 encoding
44+
/// \param[out] out a base interface OutputStream instance
45+
///
46+
/// When opening a new file, any existing file with the indicated path is
47+
/// truncated to 0 bytes, deleting any existing memory
48+
static Status Open(const std::string& path, std::shared_ptr<OutputStream>* out);
49+
50+
/// \brief Open a local file for writing
51+
/// \param[in] path with UTF8 encoding
52+
/// \param[in] append append to existing file, otherwise truncate to 0 bytes
53+
/// \param[out] out a base interface OutputStream instance
54+
static Status Open(const std::string& path, bool append,
55+
std::shared_ptr<OutputStream>* out);
56+
4257
/// \brief Open a local file for writing, truncating any existing file
4358
/// \param[in] path with UTF8 encoding
4459
/// \param[out] file a FileOutputStream instance

0 commit comments

Comments
 (0)