Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Compiled source
*.a
*.dll
*.o
*.py[ocd]
*.so
*.dylib
.build_cache_dir
MANIFEST
1 change: 0 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ if(ARROW_BUILD_TESTS)
ExternalProject_Add(gflags_ep
GIT_REPOSITORY https://github.com/gflags/gflags.git
GIT_TAG cce68f0c9c5d054017425e6e6fd54f696d36e8ee
# URL "https://github.com/gflags/gflags/archive/v${GFLAGS_VERSION}.tar.gz"
BUILD_IN_SOURCE 1
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${GFLAGS_PREFIX}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/io/io-file-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <cstdio>
#include <cstring>
#ifndef _MSC_VER
# include <fcntl.h>
#include <fcntl.h>
#endif
#include <fstream>
#include <memory>
Expand Down
25 changes: 17 additions & 8 deletions cpp/src/arrow/io/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ Status BufferOutputStream::Reserve(int64_t nbytes) {
// ----------------------------------------------------------------------
// In-memory buffer reader

BufferReader::BufferReader(const uint8_t* buffer, int buffer_size)
: buffer_(buffer), buffer_size_(buffer_size), position_(0) {}
BufferReader::BufferReader(const std::shared_ptr<Buffer>& buffer)
: buffer_(buffer), data_(buffer->data()), size_(buffer->size()), position_(0) {}

BufferReader::BufferReader(const uint8_t* data, int64_t size)
: buffer_(nullptr), data_(data), size_(size), position_(0) {}

BufferReader::~BufferReader() {}

Expand All @@ -278,26 +281,32 @@ bool BufferReader::supports_zero_copy() const {
}

Status BufferReader::Read(int64_t nbytes, int64_t* bytes_read, uint8_t* buffer) {
memcpy(buffer, buffer_ + position_, nbytes);
*bytes_read = std::min(nbytes, buffer_size_ - position_);
memcpy(buffer, data_ + position_, nbytes);
*bytes_read = std::min(nbytes, size_ - position_);
position_ += *bytes_read;
return Status::OK();
}

Status BufferReader::Read(int64_t nbytes, std::shared_ptr<Buffer>* out) {
int64_t size = std::min(nbytes, buffer_size_ - position_);
*out = std::make_shared<Buffer>(buffer_ + position_, size);
int64_t size = std::min(nbytes, size_ - position_);

if (buffer_ != nullptr) {
*out = SliceBuffer(buffer_, position_, size);
} else {
*out = std::make_shared<Buffer>(data_ + position_, size);
}

position_ += nbytes;
return Status::OK();
}

Status BufferReader::GetSize(int64_t* size) {
*size = buffer_size_;
*size = size_;
return Status::OK();
}

Status BufferReader::Seek(int64_t position) {
if (position < 0 || position >= buffer_size_) {
if (position < 0 || position >= size_) {
return Status::IOError("position out of bounds");
}

Expand Down
8 changes: 5 additions & 3 deletions cpp/src/arrow/io/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class ARROW_EXPORT MemoryMappedFile : public ReadWriteFileInterface {

class ARROW_EXPORT BufferReader : public ReadableFileInterface {
public:
BufferReader(const uint8_t* buffer, int buffer_size);
explicit BufferReader(const std::shared_ptr<Buffer>& buffer);
BufferReader(const uint8_t* data, int64_t size);
~BufferReader();

Status Close() override;
Expand All @@ -116,8 +117,9 @@ class ARROW_EXPORT BufferReader : public ReadableFileInterface {
bool supports_zero_copy() const override;

private:
const uint8_t* buffer_;
int buffer_size_;
std::shared_ptr<Buffer> buffer_;
const uint8_t* data_;
int64_t size_;
int64_t position_;
};

Expand Down
Loading