Class: Zlib::ZStream

Inherits:
Object show all
Defined in:
lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb

Direct Known Subclasses

Inflate

Instance Method Summary collapse

Constructor Details

#initializeZStream

Returns a new instance of ZStream.



54
55
56
57
58
59
60
61
62
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 54

def initialize
  @input_buffer = []
  @output_buffer = []
  @out_pos = -1
  @in_pos = -1
  @bit_bucket = 0
  @bit_count = 0

end

Instance Method Details

#adlerObject

Returns the adler-32 checksum of the input data.



64
65
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 64

def adler
end

#avail_inObject

Returns the number of bytes read. Normally 0 since all bytes are read at once.



68
69
70
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 68

def avail_in
  @input_buffer.length - @in_pos
end

#avail_outObject

Returns number of free bytes in the output buffer. As the output buffer is self expanding this normally returns 0.



73
74
75
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 73

def avail_out
  @output_buffer.length - @out_pos
end

#avail_out=(size) ⇒ Object

Allocates size bytes in output buffer. If size < avail_out it truncates the buffer.



78
79
80
81
82
83
84
85
86
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 78

def avail_out= size
  size.times do
    if size > avail_out
      @output_buffer.push nil
    else
      @output_buffer.pop
    end
  end
end

#closeObject

Closes stream. Further operations will raise Zlib::StreamError



89
90
91
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 89

def close
  @closed = true
end

#closed?Boolean

True if stream closed, otherwise False.

Returns:

  • (Boolean)


94
95
96
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 94

def closed?
  @closed
end

#data_typeObject

Best guess of input data, one of Zlib::BINARY, Zlib::ASCII, or Zlib::UNKNOWN



99
100
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 99

def data_type
end

#endObject

See close



103
104
105
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 103

def end
  close
end

#ended?Boolean

See closed?

Returns:

  • (Boolean)


108
109
110
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 108

def ended?
  closed?
end

#finishObject

Finishes the stream, flushes output buffer, implemented by child classes



113
114
115
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 113

def finish
  close
end

#finished?Boolean

True if stream is finished, otherwise False

Returns:

  • (Boolean)


118
119
120
121
122
123
124
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 118

def finished?
  if @finished.nil? then
    false
  else
    @finished
  end
end

#flush_next_inObject

Flushes input buffer and returns the data therein.



127
128
129
130
131
132
133
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 127

def flush_next_in
  @in_pos = @input_buffer.length
  @finished = true
  ret = @input_buffer.pack("c*")
  @input_buffer = []
  ret
end

#flush_next_outObject

Flushes the output buffer and returns all the data



136
137
138
139
140
141
142
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 136

def flush_next_out
  @out_pos = @output_buffer.length
  @finished = true
  ret = @output_buffer.pack("c*")
  @output_buffer = []
  ret
end

#resetObject

Reset stream. Input and Output buffers are reset.



145
146
147
148
149
150
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 145

def reset
  @out_pos = -1
  @in_pos = -1
  @input_buffer = []
  @output_buffer = []
end

#stream_end?Boolean

See finished.

Returns:

  • (Boolean)


153
154
155
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 153

def stream_end?
  finished?
end

#total_inObject

Size of input buffer.



158
159
160
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 158

def total_in
  @input_buffer.length
end

#total_outObject

Size of output buffer.



163
164
165
# File 'lib/motion-bundler/mocks/zliby-0.0.5/zlib.rb', line 163

def total_out
  @output_buffer.length
end