]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file | |
3 | // distributed with this work for additional information | |
4 | // regarding copyright ownership. The ASF licenses this file | |
5 | // to you under the Apache License, Version 2.0 (the | |
6 | // "License"); you may not use this file except in compliance | |
7 | // with the License. You may obtain a copy of the License at | |
8 | // | |
9 | // http://www.apache.org/licenses/LICENSE-2.0 | |
10 | // | |
11 | // Unless required by applicable law or agreed to in writing, | |
12 | // software distributed under the License is distributed on an | |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | // KIND, either express or implied. See the License for the | |
15 | // specific language governing permissions and limitations | |
16 | // under the License. | |
17 | ||
18 | #include "./arrow_types.h" | |
19 | ||
20 | #if defined(ARROW_R_WITH_ARROW) | |
21 | #include <arrow/io/file.h> | |
22 | #include <arrow/io/memory.h> | |
23 | ||
24 | // ------ arrow::io::Readable | |
25 | ||
26 | // [[arrow::export]] | |
27 | std::shared_ptr<arrow::Buffer> io___Readable__Read( | |
28 | const std::shared_ptr<arrow::io::Readable>& x, int64_t nbytes) { | |
29 | return ValueOrStop(x->Read(nbytes)); | |
30 | } | |
31 | ||
32 | // ------ arrow::io::InputStream | |
33 | ||
34 | // [[arrow::export]] | |
35 | void io___InputStream__Close(const std::shared_ptr<arrow::io::InputStream>& x) { | |
36 | StopIfNotOk(x->Close()); | |
37 | } | |
38 | ||
39 | // ------ arrow::io::OutputStream | |
40 | ||
41 | // [[arrow::export]] | |
42 | void io___OutputStream__Close(const std::shared_ptr<arrow::io::OutputStream>& x) { | |
43 | StopIfNotOk(x->Close()); | |
44 | } | |
45 | ||
46 | // ------ arrow::io::RandomAccessFile | |
47 | ||
48 | // [[arrow::export]] | |
49 | int64_t io___RandomAccessFile__GetSize( | |
50 | const std::shared_ptr<arrow::io::RandomAccessFile>& x) { | |
51 | return ValueOrStop(x->GetSize()); | |
52 | } | |
53 | ||
54 | // [[arrow::export]] | |
55 | bool io___RandomAccessFile__supports_zero_copy( | |
56 | const std::shared_ptr<arrow::io::RandomAccessFile>& x) { | |
57 | return x->supports_zero_copy(); | |
58 | } | |
59 | ||
60 | // [[arrow::export]] | |
61 | void io___RandomAccessFile__Seek(const std::shared_ptr<arrow::io::RandomAccessFile>& x, | |
62 | int64_t position) { | |
63 | StopIfNotOk(x->Seek(position)); | |
64 | } | |
65 | ||
66 | // [[arrow::export]] | |
67 | int64_t io___RandomAccessFile__Tell( | |
68 | const std::shared_ptr<arrow::io::RandomAccessFile>& x) { | |
69 | return ValueOrStop(x->Tell()); | |
70 | } | |
71 | ||
72 | // [[arrow::export]] | |
73 | std::shared_ptr<arrow::Buffer> io___RandomAccessFile__Read0( | |
74 | const std::shared_ptr<arrow::io::RandomAccessFile>& x) { | |
75 | int64_t current = ValueOrStop(x->Tell()); | |
76 | ||
77 | int64_t n = ValueOrStop(x->GetSize()); | |
78 | ||
79 | return ValueOrStop(x->Read(n - current)); | |
80 | } | |
81 | ||
82 | // [[arrow::export]] | |
83 | std::shared_ptr<arrow::Buffer> io___RandomAccessFile__ReadAt( | |
84 | const std::shared_ptr<arrow::io::RandomAccessFile>& x, int64_t position, | |
85 | int64_t nbytes) { | |
86 | return ValueOrStop(x->ReadAt(position, nbytes)); | |
87 | } | |
88 | ||
89 | // ------ arrow::io::MemoryMappedFile | |
90 | ||
91 | // [[arrow::export]] | |
92 | std::shared_ptr<arrow::io::MemoryMappedFile> io___MemoryMappedFile__Create( | |
93 | const std::string& path, int64_t size) { | |
94 | return ValueOrStop(arrow::io::MemoryMappedFile::Create(path, size)); | |
95 | } | |
96 | ||
97 | // [[arrow::export]] | |
98 | std::shared_ptr<arrow::io::MemoryMappedFile> io___MemoryMappedFile__Open( | |
99 | const std::string& path, arrow::io::FileMode::type mode) { | |
100 | return ValueOrStop(arrow::io::MemoryMappedFile::Open(path, mode)); | |
101 | } | |
102 | ||
103 | // [[arrow::export]] | |
104 | void io___MemoryMappedFile__Resize(const std::shared_ptr<arrow::io::MemoryMappedFile>& x, | |
105 | int64_t size) { | |
106 | StopIfNotOk(x->Resize(size)); | |
107 | } | |
108 | ||
109 | // ------ arrow::io::ReadableFile | |
110 | ||
111 | // [[arrow::export]] | |
112 | std::shared_ptr<arrow::io::ReadableFile> io___ReadableFile__Open( | |
113 | const std::string& path) { | |
114 | return ValueOrStop(arrow::io::ReadableFile::Open(path, gc_memory_pool())); | |
115 | } | |
116 | ||
117 | // ------ arrow::io::BufferReader | |
118 | ||
119 | // [[arrow::export]] | |
120 | std::shared_ptr<arrow::io::BufferReader> io___BufferReader__initialize( | |
121 | const std::shared_ptr<arrow::Buffer>& buffer) { | |
122 | return std::make_shared<arrow::io::BufferReader>(buffer); | |
123 | } | |
124 | ||
125 | // ------- arrow::io::Writable | |
126 | ||
127 | // [[arrow::export]] | |
128 | void io___Writable__write(const std::shared_ptr<arrow::io::Writable>& stream, | |
129 | const std::shared_ptr<arrow::Buffer>& buf) { | |
130 | StopIfNotOk(stream->Write(buf->data(), buf->size())); | |
131 | } | |
132 | ||
133 | // ------- arrow::io::OutputStream | |
134 | ||
135 | // [[arrow::export]] | |
136 | int64_t io___OutputStream__Tell(const std::shared_ptr<arrow::io::OutputStream>& stream) { | |
137 | return ValueOrStop(stream->Tell()); | |
138 | } | |
139 | ||
140 | // ------ arrow::io::FileOutputStream | |
141 | ||
142 | // [[arrow::export]] | |
143 | std::shared_ptr<arrow::io::FileOutputStream> io___FileOutputStream__Open( | |
144 | const std::string& path) { | |
145 | return ValueOrStop(arrow::io::FileOutputStream::Open(path)); | |
146 | } | |
147 | ||
148 | // ------ arrow::BufferOutputStream | |
149 | ||
150 | // [[arrow::export]] | |
151 | std::shared_ptr<arrow::io::BufferOutputStream> io___BufferOutputStream__Create( | |
152 | int64_t initial_capacity) { | |
153 | return ValueOrStop( | |
154 | arrow::io::BufferOutputStream::Create(initial_capacity, gc_memory_pool())); | |
155 | } | |
156 | ||
157 | // [[arrow::export]] | |
158 | int64_t io___BufferOutputStream__capacity( | |
159 | const std::shared_ptr<arrow::io::BufferOutputStream>& stream) { | |
160 | return stream->capacity(); | |
161 | } | |
162 | ||
163 | // [[arrow::export]] | |
164 | std::shared_ptr<arrow::Buffer> io___BufferOutputStream__Finish( | |
165 | const std::shared_ptr<arrow::io::BufferOutputStream>& stream) { | |
166 | return ValueOrStop(stream->Finish()); | |
167 | } | |
168 | ||
169 | // [[arrow::export]] | |
170 | int64_t io___BufferOutputStream__Tell( | |
171 | const std::shared_ptr<arrow::io::BufferOutputStream>& stream) { | |
172 | return ValueOrStop(stream->Tell()); | |
173 | } | |
174 | ||
175 | // [[arrow::export]] | |
176 | void io___BufferOutputStream__Write( | |
177 | const std::shared_ptr<arrow::io::BufferOutputStream>& stream, cpp11::raws bytes) { | |
178 | StopIfNotOk(stream->Write(RAW(bytes), bytes.size())); | |
179 | } | |
180 | ||
181 | #endif |