ioblockreader 1.0.2.20130613 → 1.0.3.20130618
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.
- data/AUTHORS +1 -0
- data/ChangeLog +4 -0
- data/README.md +17 -0
- data/ReleaseInfo +1 -1
- data/lib/ioblockreader/ioblockreader.rb +25 -0
- metadata +2 -2
data/AUTHORS
CHANGED
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -124,6 +124,23 @@ end
|
|
124
124
|
|
125
125
|
```
|
126
126
|
|
127
|
+
### IOBlockReader#get_block_containing_offset(offset = 0)
|
128
|
+
|
129
|
+
Get the block containing a given offset.
|
130
|
+
This method is mainly used to provide some low-level access for processes needing great parsing performance.
|
131
|
+
|
132
|
+
Parameters:
|
133
|
+
* **offset** ( _Fixnum_ ): The offset to be accessed [default = 0]
|
134
|
+
Return:
|
135
|
+
* _String_ : The block of data containing this offset
|
136
|
+
* _Fixnum_ : The beginning offset of this data block
|
137
|
+
* _Boolean_ : Is this block the last one?
|
138
|
+
|
139
|
+
Example:
|
140
|
+
```
|
141
|
+
str_data, begin_offset, last_one = content.get_block_containing_offset(20)
|
142
|
+
```
|
143
|
+
|
127
144
|
## Contact
|
128
145
|
|
129
146
|
Want to contribute? Have any questions? [Contact Muriel!](muriel@x-aeon.com)
|
data/ReleaseInfo
CHANGED
@@ -270,6 +270,31 @@ module IOBlockReader
|
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
273
|
+
# Get the block containing a given offset.
|
274
|
+
# This method is mainly used to provide some low-level access for processes needing great parsing performance.
|
275
|
+
#
|
276
|
+
# Parameters::
|
277
|
+
# * *offset* (_Fixnum_): The offset to be accessed [default = 0]
|
278
|
+
# Return::
|
279
|
+
# * _String_: The block of data containing this offset
|
280
|
+
# * _Fixnum_: The beginning offset of this data block
|
281
|
+
# * _Boolean_: Is this block the last one?
|
282
|
+
def get_block_containing_offset(offset = 0)
|
283
|
+
#puts "[IOBlockReader] - get_block_containing_offset(#{offset})"
|
284
|
+
# Use the cache if possible
|
285
|
+
return [ @cached_block.data, @cached_block.offset, @cached_block.last_block? ] if ((@cached_block != nil) and (offset >= @cached_block.offset) and (offset < @cached_block_end_offset))
|
286
|
+
#puts "[IOBlockReader] - get_block_containing_offset(#{offset}) - Cache miss"
|
287
|
+
single_block_index, _ = offset.divmod(@block_size)
|
288
|
+
if ((block = @blocks[single_block_index]) == nil)
|
289
|
+
read_needed_blocks([single_block_index], single_block_index, single_block_index)
|
290
|
+
block = @blocks[single_block_index]
|
291
|
+
else
|
292
|
+
block.touch
|
293
|
+
end
|
294
|
+
set_cache_block(block)
|
295
|
+
return block.data, block.offset, block.last_block?
|
296
|
+
end
|
297
|
+
|
273
298
|
private
|
274
299
|
|
275
300
|
# Set the new cache block
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ioblockreader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3.20130618
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby library giving block-buffered and cached read over IO objects with
|
15
15
|
a String-like interface. Ideal to parse big files as Strings, limiting memory consumption.
|