large_file_linux 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/ext/large_file_linux/extconf.rb +3 -0
- data/ext/large_file_linux/large_file_linux.c +468 -0
- data/large_file_linux.gemspec +35 -0
- data/lib/large_file_linux.rb +2 -0
- data/lib/large_file_linux/version.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 455ad5af8aa1ea9f80d519551eba7a2b59461c51
|
4
|
+
data.tar.gz: 9e758574a2fb1496a305d270cefbad46f9aa089e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 898a6ae8190c8b45df5d915942387f1d079bcd87897417215c22c6b50064ae7dae7fd94fe9261dd74c453d1ec99e1829062553026e1dba70675d43aa2de12cfc
|
7
|
+
data.tar.gz: a10abc3fe2b3875bd06d2139d98610024e03ad5097b3a001c9a52108c9edd8a27f666c1a9fb455028b3c8ae998ba4e77e32aaefbd02becbd6e26ddcb8920411b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Red Hat, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# LargeFileLinux
|
2
|
+
|
3
|
+
Ruby class to read large files on 32 bit Linux platforms.
|
4
|
+
|
5
|
+
[](http://badge.fury.io/rb/large_file_linux)
|
6
|
+
[](https://travis-ci.org/ManageIQ/large_file_linux)
|
7
|
+
[](https://gemnasium.com/ManageIQ/large_file_linux)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'large_file_linux'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install large_file_linux
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
LargeFileLinux supports `#read`, `#write`, `#seek`, `#size`, and `#close`, much
|
28
|
+
like the Ruby `File` class.
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ManageIQ/large_file_linux.
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rake/extensiontask'
|
4
|
+
Rake::ExtensionTask.new do |ext|
|
5
|
+
ext.name = 'large_file_linux'
|
6
|
+
ext.ext_dir = 'ext/large_file_linux'
|
7
|
+
ext.lib_dir = 'lib/large_file_linux'
|
8
|
+
end
|
9
|
+
|
10
|
+
require "rspec/core/rake_task"
|
11
|
+
RSpec::Core::RakeTask.new(:spec => :compile)
|
12
|
+
|
13
|
+
task :default => :spec
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "large_file_linux"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,468 @@
|
|
1
|
+
/*
|
2
|
+
* Ruby module to read large files on Linux platforms.
|
3
|
+
*/
|
4
|
+
|
5
|
+
#define _LARGEFILE64_SOURCE
|
6
|
+
|
7
|
+
#include <sys/types.h>
|
8
|
+
#include <sys/stat.h>
|
9
|
+
#include <unistd.h>
|
10
|
+
#include <fcntl.h>
|
11
|
+
#include <stdio.h>
|
12
|
+
#include <errno.h>
|
13
|
+
#include <string.h>
|
14
|
+
|
15
|
+
#include "ruby.h"
|
16
|
+
|
17
|
+
#define CLOSED_FD -1
|
18
|
+
|
19
|
+
static const char *class_name = "LargeFileLinux";
|
20
|
+
|
21
|
+
/*
|
22
|
+
* Called by GC when this object is free.
|
23
|
+
* Close the file if it is open.
|
24
|
+
*/
|
25
|
+
static void
|
26
|
+
lf_free(void *p) {
|
27
|
+
if (*(int *)p == -1) return;
|
28
|
+
close(*(int *)p);
|
29
|
+
free(p);
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
* Private data allocation.
|
34
|
+
*
|
35
|
+
* We wrap the storage for the file descriptor so we can close
|
36
|
+
* the file when GC frees this object.
|
37
|
+
*/
|
38
|
+
static VALUE
|
39
|
+
lf_alloc(VALUE klass) {
|
40
|
+
VALUE obj;
|
41
|
+
int *fdp;
|
42
|
+
|
43
|
+
/*
|
44
|
+
* Allocate instance-specific storage for the file descriptor.
|
45
|
+
*/
|
46
|
+
if ((fdp = malloc(sizeof(int))) == NULL) {
|
47
|
+
rb_raise(rb_eNoMemError,
|
48
|
+
"%s::alloc - could not allocate memory for private data\n",
|
49
|
+
class_name);
|
50
|
+
}
|
51
|
+
/*
|
52
|
+
* Wrap the fd storage and register a routine to free it.
|
53
|
+
*/
|
54
|
+
obj = Data_Wrap_Struct(klass, 0, lf_free, fdp);
|
55
|
+
*fdp = CLOSED_FD;
|
56
|
+
|
57
|
+
return obj;
|
58
|
+
}
|
59
|
+
|
60
|
+
/*
|
61
|
+
* The "initialize" method.
|
62
|
+
*/
|
63
|
+
static VALUE
|
64
|
+
lf_init(VALUE self, VALUE fname, VALUE rflags) {
|
65
|
+
char *fnp, *rffp;
|
66
|
+
int fd, *fdp, flags;
|
67
|
+
|
68
|
+
/*
|
69
|
+
* Get the C-language representations of the Ruby
|
70
|
+
* objects passed in.
|
71
|
+
*/
|
72
|
+
fnp = RSTRING_PTR(StringValue(fname));
|
73
|
+
rffp = RSTRING_PTR(StringValue(rflags));
|
74
|
+
|
75
|
+
# ifdef DEBUG
|
76
|
+
printf("LargeFileLinux[0x%lx] (new): file = %s, flags = %s\n", self, fnp, rffp);
|
77
|
+
# endif
|
78
|
+
|
79
|
+
/*
|
80
|
+
* Convert Ruby form of "open" flags to open(2) bit flags.
|
81
|
+
*/
|
82
|
+
flags = O_LARGEFILE;
|
83
|
+
switch(*rffp) {
|
84
|
+
case 'r':
|
85
|
+
if (*++rffp == '+') flags |= O_RDWR; // Read/write: "r+"
|
86
|
+
else flags |= O_RDONLY; // Read-only: "r"
|
87
|
+
break;
|
88
|
+
|
89
|
+
case 'w':
|
90
|
+
flags |= O_CREAT | O_TRUNC;
|
91
|
+
if (*++rffp == '+') flags |= O_RDWR; // Read/write, trincate or create: "w+"
|
92
|
+
else flags |= O_WRONLY; // Write-only, truncate or create: "w"
|
93
|
+
break;
|
94
|
+
|
95
|
+
case 'a':
|
96
|
+
flags |= O_CREAT | O_APPEND;
|
97
|
+
if (*++rffp == '+') flags |= O_RDWR; // Read/write, append or create: "a+"
|
98
|
+
else flags |= O_WRONLY; // Write-only, append or create: "a"
|
99
|
+
break;
|
100
|
+
|
101
|
+
case 'b': // Binary mode, no-op on linux
|
102
|
+
break;
|
103
|
+
|
104
|
+
default:
|
105
|
+
rb_raise(rb_eArgError,
|
106
|
+
"%s::new on file: %s - unrecognized flag value: %c\n",
|
107
|
+
class_name, fnp, *rffp);
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* Open the file.
|
112
|
+
*/
|
113
|
+
if ((fd = open(fnp, flags)) < 0) {
|
114
|
+
rb_raise(rb_eSystemCallError,
|
115
|
+
"%s::new - open failed for file: %s, %s\n",
|
116
|
+
class_name, fnp, strerror(errno));
|
117
|
+
}
|
118
|
+
|
119
|
+
/*
|
120
|
+
* Save the file name and file descriptor in instance variables.
|
121
|
+
*/
|
122
|
+
rb_iv_set(self, "@fileName", rb_str_new2(fnp));
|
123
|
+
|
124
|
+
/*
|
125
|
+
* Set the file descriptor in private data space.
|
126
|
+
*/
|
127
|
+
Data_Get_Struct(self, int, fdp);
|
128
|
+
*fdp = fd;
|
129
|
+
|
130
|
+
# ifdef DEBUG
|
131
|
+
printf("LargeFileLinux[0x%lx] (init): fd = %d\n", self, *fdp);
|
132
|
+
# endif
|
133
|
+
|
134
|
+
return self;
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
* The "read" instance method.
|
139
|
+
*/
|
140
|
+
static VALUE
|
141
|
+
lf_read(VALUE self, VALUE bytes) {
|
142
|
+
VALUE rb;
|
143
|
+
int *fdp;
|
144
|
+
char *buf;
|
145
|
+
long len;
|
146
|
+
int n = NUM2INT(bytes); // the number of bytes to read
|
147
|
+
|
148
|
+
/*
|
149
|
+
* Get the file descriptor from private data space.
|
150
|
+
*/
|
151
|
+
Data_Get_Struct(self, int, fdp);
|
152
|
+
|
153
|
+
# ifdef DEBUG
|
154
|
+
printf("LargeFileLinux [0x%lx] (read): bytes = %d, fd = %d\n", self, n, *fdp);
|
155
|
+
# endif
|
156
|
+
|
157
|
+
/*
|
158
|
+
* Make sure we don't try to read a file we've closed.
|
159
|
+
*/
|
160
|
+
if (*fdp == CLOSED_FD) {
|
161
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
162
|
+
# ifdef DEBUG
|
163
|
+
printf("LargeFileLinux [0x%lx] (read): failed on file (fd = %d): %s, attempted read after close\n",
|
164
|
+
self,
|
165
|
+
*fdp,
|
166
|
+
RSTRING_PTR(StringValue(v)));
|
167
|
+
# endif
|
168
|
+
rb_raise(rb_eSystemCallError,
|
169
|
+
"%s::read - read failed on file: %s, attempted read after close\n",
|
170
|
+
class_name,
|
171
|
+
RSTRING_PTR(StringValue(v)));
|
172
|
+
}
|
173
|
+
|
174
|
+
/*
|
175
|
+
* Allocate a temp read buffer.
|
176
|
+
*/
|
177
|
+
if ((buf = malloc(n)) == NULL) {
|
178
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
179
|
+
# ifdef DEBUG
|
180
|
+
printf("LargeFileLinux [0x%lx] (read): on file (fd = %d): %s - could not allocate memory for read buffer\n",
|
181
|
+
self,
|
182
|
+
*fdp,
|
183
|
+
RSTRING_PTR(StringValue(v)));
|
184
|
+
# endif
|
185
|
+
rb_raise(rb_eNoMemError,
|
186
|
+
"%s::read on file: %s - could not allocate memory for read buffer\n",
|
187
|
+
class_name,
|
188
|
+
RSTRING_PTR(StringValue(v)));
|
189
|
+
}
|
190
|
+
|
191
|
+
/*
|
192
|
+
* Read data into the temp buffer.
|
193
|
+
*/
|
194
|
+
if ((len = read(*fdp, buf, n)) < 0) {
|
195
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
196
|
+
# ifdef DEBUG
|
197
|
+
printf("LargeFileLinux [0x%lx] (read): failed on file (fd = %d): %s, %s\n",
|
198
|
+
self,
|
199
|
+
*fdp,
|
200
|
+
RSTRING_PTR(StringValue(v)),
|
201
|
+
strerror(errno));
|
202
|
+
# endif
|
203
|
+
rb_raise(rb_eSystemCallError,
|
204
|
+
"%s::read - read failed on file: %s, %s\n",
|
205
|
+
class_name,
|
206
|
+
RSTRING_PTR(StringValue(v)),
|
207
|
+
strerror(errno));
|
208
|
+
}
|
209
|
+
|
210
|
+
/*
|
211
|
+
* Create a Ruby string and initialize it with the
|
212
|
+
* contents of the temp buffer.
|
213
|
+
*/
|
214
|
+
rb = rb_str_new(buf, len);
|
215
|
+
// we no longer need the temp buffer.
|
216
|
+
free(buf);
|
217
|
+
// return the ruby string.
|
218
|
+
return rb;
|
219
|
+
}
|
220
|
+
|
221
|
+
/*
|
222
|
+
* The "write" instance method.
|
223
|
+
*/
|
224
|
+
static VALUE
|
225
|
+
lf_write(VALUE self, VALUE buf, VALUE bytes) {
|
226
|
+
int *fdp;
|
227
|
+
char *bufp;
|
228
|
+
long len;
|
229
|
+
int n = NUM2INT(bytes); // the number of bytes to write
|
230
|
+
|
231
|
+
/*
|
232
|
+
* Get the file descriptor from private data space.
|
233
|
+
*/
|
234
|
+
Data_Get_Struct(self, int, fdp);
|
235
|
+
|
236
|
+
# ifdef DEBUG
|
237
|
+
printf("LargeFileLinux [0x%lx] (write): bytes = %d, fd = %d\n", self, n, *fdp);
|
238
|
+
# endif
|
239
|
+
|
240
|
+
/*
|
241
|
+
* Make sure we don't try to write a file we've closed.
|
242
|
+
*/
|
243
|
+
if (*fdp == CLOSED_FD) {
|
244
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
245
|
+
# ifdef DEBUG
|
246
|
+
printf("LargeFileLinux [0x%lx] (write): write failed on file (fd = %d): %s, attempted read after close\n",
|
247
|
+
self,
|
248
|
+
*fdp,
|
249
|
+
RSTRING_PTR(StringValue(v)));
|
250
|
+
# endif
|
251
|
+
rb_raise(rb_eSystemCallError,
|
252
|
+
"%s::write - write failed on file: %s, attempted read after close\n",
|
253
|
+
class_name,
|
254
|
+
RSTRING_PTR(StringValue(v)));
|
255
|
+
}
|
256
|
+
|
257
|
+
bufp = RSTRING_PTR(StringValue(buf));
|
258
|
+
|
259
|
+
/*
|
260
|
+
* Write data to file.
|
261
|
+
*/
|
262
|
+
if ((len = write(*fdp, bufp, n)) < 0) {
|
263
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
264
|
+
# ifdef DEBUG
|
265
|
+
printf("LargeFileLinux [0x%lx] (write): write failed on file (fd = %d): %s, %s\n",
|
266
|
+
self,
|
267
|
+
*fdp,
|
268
|
+
RSTRING_PTR(StringValue(v)),
|
269
|
+
strerror(errno));
|
270
|
+
# endif
|
271
|
+
rb_raise(rb_eSystemCallError,
|
272
|
+
"%s::write - write failed on file (fd = %d): %s, %s\n",
|
273
|
+
class_name,
|
274
|
+
*fdp,
|
275
|
+
RSTRING_PTR(StringValue(v)),
|
276
|
+
strerror(errno));
|
277
|
+
}
|
278
|
+
|
279
|
+
return INT2NUM(len);
|
280
|
+
}
|
281
|
+
|
282
|
+
/*
|
283
|
+
* The "seek" instance method.
|
284
|
+
*/
|
285
|
+
static VALUE
|
286
|
+
lf_seek(VALUE self, VALUE offset, VALUE whence) {
|
287
|
+
int *fdp;
|
288
|
+
long long o;
|
289
|
+
|
290
|
+
/*
|
291
|
+
* Get the file descriptor from private data space.
|
292
|
+
*/
|
293
|
+
Data_Get_Struct(self, int, fdp);
|
294
|
+
|
295
|
+
/*
|
296
|
+
* The offset value passed in is either a Fixnum or Bignum,
|
297
|
+
* convert accordingly.
|
298
|
+
*/
|
299
|
+
if (FIXNUM_P(offset)) {
|
300
|
+
o = (long long)NUM2INT(offset);
|
301
|
+
}
|
302
|
+
else {
|
303
|
+
o = rb_big2ll(offset);
|
304
|
+
}
|
305
|
+
|
306
|
+
# ifdef DEBUG
|
307
|
+
printf("LargeFileLinux [0x%lx] (seek): offset = %lld, whence = %d, fd = %d\n",
|
308
|
+
self, o, NUM2INT(whence), *fdp);
|
309
|
+
# endif
|
310
|
+
|
311
|
+
/*
|
312
|
+
* Make sure we don't try to seek on a file we've closed.
|
313
|
+
*/
|
314
|
+
if (*fdp == CLOSED_FD) {
|
315
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
316
|
+
rb_raise(rb_eSystemCallError,
|
317
|
+
"%s::seek - seek failed on file: %s, attempted seek after close\n",
|
318
|
+
class_name,
|
319
|
+
RSTRING_PTR(StringValue(v)));
|
320
|
+
}
|
321
|
+
|
322
|
+
/*
|
323
|
+
* Perform seek operation on the file.
|
324
|
+
*
|
325
|
+
* This code assumes the values of the Ruby IO::SEEK_* constants
|
326
|
+
* and their corresponding C-library equivalents, are the same.
|
327
|
+
*/
|
328
|
+
if (lseek64(*fdp, o, NUM2INT(whence)) < 0) {
|
329
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
330
|
+
rb_raise(rb_eSystemCallError,
|
331
|
+
"%s::seek - seek failed on file: %s, %s\n",
|
332
|
+
class_name,
|
333
|
+
RSTRING_PTR(StringValue(v)),
|
334
|
+
strerror(errno));
|
335
|
+
}
|
336
|
+
|
337
|
+
return INT2NUM(0);
|
338
|
+
}
|
339
|
+
|
340
|
+
/*
|
341
|
+
* The "size" instance method.
|
342
|
+
*/
|
343
|
+
static VALUE
|
344
|
+
lf_size(VALUE self) {
|
345
|
+
struct stat64 st;
|
346
|
+
int *fdp;
|
347
|
+
|
348
|
+
/*
|
349
|
+
* Get the file descriptor from private data space.
|
350
|
+
*/
|
351
|
+
Data_Get_Struct(self, int, fdp);
|
352
|
+
|
353
|
+
# ifdef DEBUG
|
354
|
+
printf("LargeFileLinux [0x%lx] (size): fd = %d\n", self, *fdp);
|
355
|
+
# endif
|
356
|
+
|
357
|
+
if (*fdp == CLOSED_FD) {
|
358
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
359
|
+
rb_raise(rb_eSystemCallError,
|
360
|
+
"%s::size - failed on file: %s, file is not open\n",
|
361
|
+
class_name,
|
362
|
+
RSTRING_PTR(StringValue(v)));
|
363
|
+
}
|
364
|
+
|
365
|
+
/*
|
366
|
+
* stat the file to get its size.
|
367
|
+
*/
|
368
|
+
if (fstat64(*fdp, &st) < 0) {
|
369
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
370
|
+
rb_raise(rb_eSystemCallError,
|
371
|
+
"%s::size - stat failed on file: %s, %s\n",
|
372
|
+
class_name,
|
373
|
+
RSTRING_PTR(StringValue(v)),
|
374
|
+
strerror(errno));
|
375
|
+
}
|
376
|
+
|
377
|
+
return OFFT2NUM(st.st_size);
|
378
|
+
}
|
379
|
+
|
380
|
+
/*
|
381
|
+
* The "size" class method.
|
382
|
+
*/
|
383
|
+
static VALUE
|
384
|
+
lf_s_size(VALUE self, VALUE fname) {
|
385
|
+
char *fnp;
|
386
|
+
struct stat64 st;
|
387
|
+
|
388
|
+
/*
|
389
|
+
* Get the C-language representations of the Ruby
|
390
|
+
* objects passed in.
|
391
|
+
*/
|
392
|
+
fnp = RSTRING_PTR(StringValue(fname));
|
393
|
+
|
394
|
+
# ifdef DEBUG
|
395
|
+
printf("LargeFileLinux [0x%lx] (s_size): file = %s\n", self, *fnp);
|
396
|
+
# endif
|
397
|
+
|
398
|
+
/*
|
399
|
+
* stat the file to get its size.
|
400
|
+
*/
|
401
|
+
if (stat64(fnp, &st) < 0) {
|
402
|
+
rb_raise(rb_eSystemCallError,
|
403
|
+
"%s::s_size - stat failed on file: %s, %s\n",
|
404
|
+
class_name,
|
405
|
+
fnp,
|
406
|
+
strerror(errno));
|
407
|
+
}
|
408
|
+
|
409
|
+
return OFFT2NUM(st.st_size);
|
410
|
+
}
|
411
|
+
|
412
|
+
/*
|
413
|
+
* The "close" instance method.
|
414
|
+
*/
|
415
|
+
static VALUE
|
416
|
+
lf_close(VALUE self) {
|
417
|
+
int *fdp;
|
418
|
+
|
419
|
+
/*
|
420
|
+
* Get the file descriptor from private data space.
|
421
|
+
*/
|
422
|
+
Data_Get_Struct(self, int, fdp);
|
423
|
+
|
424
|
+
# ifdef DEBUG
|
425
|
+
do {
|
426
|
+
VALUE v = rb_iv_get(self, "@fileName");
|
427
|
+
printf("LargeFileLinux [0x%lx] (close): fd = %d, File = %s\n", self, *fdp, RSTRING_PTR(StringValue(v)));
|
428
|
+
} while(0);
|
429
|
+
# endif
|
430
|
+
|
431
|
+
if (*fdp != CLOSED_FD) {
|
432
|
+
close(*fdp);
|
433
|
+
*fdp = CLOSED_FD;
|
434
|
+
}
|
435
|
+
return Qnil;
|
436
|
+
}
|
437
|
+
|
438
|
+
VALUE cLargeFileLinux;
|
439
|
+
|
440
|
+
/*
|
441
|
+
* Initialize the class.
|
442
|
+
*/
|
443
|
+
void Init_large_file_linux() {
|
444
|
+
/*
|
445
|
+
* Define the class.
|
446
|
+
*/
|
447
|
+
cLargeFileLinux = rb_define_class(class_name, rb_cObject);
|
448
|
+
|
449
|
+
/*
|
450
|
+
* Define method to allocate private data.
|
451
|
+
*/
|
452
|
+
rb_define_alloc_func(cLargeFileLinux, lf_alloc);
|
453
|
+
|
454
|
+
/*
|
455
|
+
* Define the class' instance methods.
|
456
|
+
*/
|
457
|
+
rb_define_method(cLargeFileLinux, "initialize", lf_init, 2);
|
458
|
+
rb_define_method(cLargeFileLinux, "read", lf_read, 1);
|
459
|
+
rb_define_method(cLargeFileLinux, "write", lf_write, 2);
|
460
|
+
rb_define_method(cLargeFileLinux, "seek", lf_seek, 2);
|
461
|
+
rb_define_method(cLargeFileLinux, "size", lf_size, 0);
|
462
|
+
rb_define_method(cLargeFileLinux, "close", lf_close, 0);
|
463
|
+
|
464
|
+
/*
|
465
|
+
* Define class methods.
|
466
|
+
*/
|
467
|
+
rb_define_singleton_method(cLargeFileLinux, "size", lf_s_size, 1);
|
468
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'large_file_linux/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "large_file_linux"
|
8
|
+
spec.version = LargeFileLinux::VERSION
|
9
|
+
spec.authors = ["Rich Oliveri", "Oleg Barenboim", "Jason Frey"]
|
10
|
+
spec.email = ["roliveri@redhat.com", "chessbyte@gmail.com", "fryguy9@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby class to read large files on 32 bit Linux platforms.}
|
13
|
+
spec.description = %q{Ruby class to read large files on 32 bit Linux platforms.}
|
14
|
+
spec.homepage = "http://github.com/ManageIQ/large_file_linux"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.extensions = ["ext/large_file_linux/extconf.rb"]
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rake-compiler"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: large_file_linux
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rich Oliveri
|
8
|
+
- Oleg Barenboim
|
9
|
+
- Jason Frey
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
|
+
cert_chain: []
|
13
|
+
date: 2015-06-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '10.0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '10.0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake-compiler
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
description: Ruby class to read large files on 32 bit Linux platforms.
|
72
|
+
email:
|
73
|
+
- roliveri@redhat.com
|
74
|
+
- chessbyte@gmail.com
|
75
|
+
- fryguy9@gmail.com
|
76
|
+
executables: []
|
77
|
+
extensions:
|
78
|
+
- ext/large_file_linux/extconf.rb
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- .gitignore
|
82
|
+
- .rspec
|
83
|
+
- .travis.yml
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- ext/large_file_linux/extconf.rb
|
91
|
+
- ext/large_file_linux/large_file_linux.c
|
92
|
+
- large_file_linux.gemspec
|
93
|
+
- lib/large_file_linux.rb
|
94
|
+
- lib/large_file_linux/version.rb
|
95
|
+
homepage: http://github.com/ManageIQ/large_file_linux
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata:
|
99
|
+
allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.14
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Ruby class to read large files on 32 bit Linux platforms.
|
120
|
+
test_files: []
|