Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:26:59

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 // Compressed stream implementations
0019 
0020 #pragma once
0021 
0022 #include <memory>
0023 #include <string>
0024 
0025 #include "arrow/io/concurrency.h"
0026 #include "arrow/io/interfaces.h"
0027 #include "arrow/util/visibility.h"
0028 
0029 namespace arrow {
0030 
0031 class MemoryPool;
0032 class Status;
0033 
0034 namespace util {
0035 
0036 class Codec;
0037 
0038 }  // namespace util
0039 
0040 namespace io {
0041 
0042 class ARROW_EXPORT CompressedOutputStream : public OutputStream {
0043  public:
0044   ~CompressedOutputStream() override;
0045 
0046   /// \brief Create a compressed output stream wrapping the given output stream.
0047   ///
0048   /// The codec must be capable of streaming compression. Some codecs,
0049   /// like Snappy, are not able to do so.
0050   static Result<std::shared_ptr<CompressedOutputStream>> Make(
0051       util::Codec* codec, const std::shared_ptr<OutputStream>& raw,
0052       MemoryPool* pool = default_memory_pool());
0053 
0054   // OutputStream interface
0055 
0056   /// \brief Close the compressed output stream.  This implicitly closes the
0057   /// underlying raw output stream.
0058   Status Close() override;
0059   Status Abort() override;
0060   bool closed() const override;
0061 
0062   Result<int64_t> Tell() const override;
0063 
0064   Status Write(const void* data, int64_t nbytes) override;
0065   /// \cond FALSE
0066   using Writable::Write;
0067   /// \endcond
0068   Status Flush() override;
0069 
0070   /// \brief Return the underlying raw output stream.
0071   std::shared_ptr<OutputStream> raw() const;
0072 
0073  private:
0074   ARROW_DISALLOW_COPY_AND_ASSIGN(CompressedOutputStream);
0075 
0076   CompressedOutputStream() = default;
0077 
0078   class ARROW_NO_EXPORT Impl;
0079   std::unique_ptr<Impl> impl_;
0080 };
0081 
0082 class ARROW_EXPORT CompressedInputStream
0083     : public internal::InputStreamConcurrencyWrapper<CompressedInputStream> {
0084  public:
0085   ~CompressedInputStream() override;
0086 
0087   /// \brief Create a compressed input stream wrapping the given input stream.
0088   ///
0089   /// The codec must be capable of streaming decompression. Some codecs,
0090   /// like Snappy, are not able to do so.
0091   static Result<std::shared_ptr<CompressedInputStream>> Make(
0092       util::Codec* codec, const std::shared_ptr<InputStream>& raw,
0093       MemoryPool* pool = default_memory_pool());
0094 
0095   // InputStream interface
0096 
0097   bool closed() const override;
0098   Result<std::shared_ptr<const KeyValueMetadata>> ReadMetadata() override;
0099   Future<std::shared_ptr<const KeyValueMetadata>> ReadMetadataAsync(
0100       const IOContext& io_context) override;
0101 
0102   /// \brief Return the underlying raw input stream.
0103   std::shared_ptr<InputStream> raw() const;
0104 
0105  private:
0106   friend InputStreamConcurrencyWrapper<CompressedInputStream>;
0107   ARROW_DISALLOW_COPY_AND_ASSIGN(CompressedInputStream);
0108 
0109   CompressedInputStream() = default;
0110 
0111   /// \brief Close the compressed input stream.  This implicitly closes the
0112   /// underlying raw input stream.
0113   Status DoClose();
0114   Status DoAbort() override;
0115   Result<int64_t> DoTell() const;
0116   Result<int64_t> DoRead(int64_t nbytes, void* out);
0117   Result<std::shared_ptr<Buffer>> DoRead(int64_t nbytes);
0118 
0119   class ARROW_NO_EXPORT Impl;
0120   std::unique_ptr<Impl> impl_;
0121 };
0122 
0123 }  // namespace io
0124 }  // namespace arrow