ioblockreader 1.0.2.20130613 → 1.0.3.20130618

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS CHANGED
@@ -3,3 +3,4 @@
3
3
  * 1.0.0.20130611
4
4
  * 1.0.1.20130611
5
5
  * 1.0.2.20130613
6
+ * 1.0.3.20130618
data/ChangeLog CHANGED
@@ -1,5 +1,9 @@
1
1
  = IOBlockReader Release History
2
2
 
3
+ == 1.0.3.20130618 (Beta)
4
+
5
+ * Added get_block_containing_offset interface
6
+
3
7
  == 1.0.2.20130613 (Beta)
4
8
 
5
9
  * Added each_block interface
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
@@ -2,7 +2,7 @@
2
2
  # This file has been generated by RubyPackager during a delivery.
3
3
  # More info about RubyPackager: http://rubypackager.sourceforge.net
4
4
  {
5
- :version => '1.0.2.20130613',
5
+ :version => '1.0.3.20130618',
6
6
  :tags => [ 'Beta' ],
7
7
  :dev_status => 'Beta'
8
8
  }
@@ -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.2.20130613
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-13 00:00:00.000000000 Z
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.