coryan commented on a change in pull request #11436:
URL: https://github.com/apache/arrow/pull/11436#discussion_r741330449



##########
File path: cpp/src/arrow/filesystem/gcsfs.cc
##########
@@ -58,9 +61,48 @@ struct GcsPath {
   }
 };
 
-}  // namespace
+class GcsInputStream : public arrow::io::InputStream {
+ public:
+  explicit GcsInputStream(gcs::ObjectReadStream stream) : 
stream_(std::move(stream)) {}
 
-namespace gcs = google::cloud::storage;
+  ~GcsInputStream() override = default;
+
+  Status Close() override {
+    stream_.Close();
+    return Status::OK();
+  }
+
+  Result<int64_t> Tell() const override {
+    if (!stream_) {
+      return Status::IOError("invalid stream");
+    }
+    return stream_.tellg();
+  }
+
+  bool closed() const override { return !stream_.IsOpen(); }
+
+  Result<int64_t> Read(int64_t nbytes, void* out) override {
+    stream_.read(static_cast<char*>(out), nbytes);
+    if (!stream_.status().ok()) {
+      return internal::ToArrowStatus(stream_.status());
+    }
+    return stream_.gcount();
+  }
+
+  Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) override {
+    ARROW_ASSIGN_OR_RAISE(auto buffer, arrow::AllocateResizableBuffer(nbytes));
+    stream_.read(reinterpret_cast<char*>(buffer->mutable_data()), nbytes);
+    if (!stream_.status().ok()) {
+      return internal::ToArrowStatus(stream_.status());
+    }
+    return arrow::SliceMutableBufferSafe(std::move(buffer), 0, 
stream_.gcount());

Review comment:
       Created https://issues.apache.org/jira/browse/ARROW-14559 to track that 
change.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to