bio-bgzf 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/bio-bgzf/writer.rb +19 -3
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,13 +1,21 @@
1
+ require 'zlib'
2
+
1
3
  module Bio::BGZF
2
4
 
3
5
  class Writer
4
6
  include Bio::BGZF
5
7
 
6
- attr_reader :f, :buf
8
+ attr_reader :f, :buf, :level
9
+
10
+ # Return the virtual offset of the last {#write} call. This is a
11
+ # hook for e.g. building an index on the fly.
12
+ attr_reader :last_write_pos
7
13
 
8
- def initialize(f)
14
+ def initialize(f, level=2)
9
15
  @f = f
16
+ @level = level
10
17
  @buf = ''
18
+ @buf_write_pos = 0
11
19
  if block_given?
12
20
  begin
13
21
  yield self
@@ -24,15 +32,22 @@ module Bio::BGZF
24
32
  def write_buf
25
33
  if buf.size > 0
26
34
  raise "Buffer too large: #{buf.bytesize}" if buf.bytesize > MAX_BYTES
27
- block = pack(buf)
35
+ block = pack(buf, level)
28
36
  f.write(block)
29
37
  @buf = ''
38
+ @buf_write_pos = tell
30
39
  end
31
40
  end
32
41
 
42
+ # @api private
43
+ def _cur_write_pos
44
+ @buf_write_pos + buf.bytesize
45
+ end
46
+
33
47
  def write(s)
34
48
  if s.bytesize > MAX_BYTES
35
49
  write_buf
50
+ @last_write_pos = _cur_write_pos
36
51
  _each_slice(s) do |slice|
37
52
  write(slice)
38
53
  end
@@ -40,6 +55,7 @@ module Bio::BGZF
40
55
  if (s.bytesize + buf.bytesize) > MAX_BYTES
41
56
  write_buf
42
57
  end
58
+ @last_write_pos = _cur_write_pos
43
59
  buf << s
44
60
  end
45
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-bgzf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-02 00:00:00.000000000 Z
13
+ date: 2012-08-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -104,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  segments:
106
106
  - 0
107
- hash: 4066832272659457160
107
+ hash: -2944900178146430147
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  none: false
110
110
  requirements: