Class: Schlepp::Sink::TableObject::Compressor::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/schlepp/sink/filter/compressor/stream.rb

Instance Method Summary collapse

Constructor Details

#initializeStream

Returns a new instance of Stream.



8
9
10
11
12
# File 'lib/schlepp/sink/filter/compressor/stream.rb', line 8

def initialize
  @buffer = StringIO.new("", "rb+")
  @compressor = Zlib::GzipWriter.new(@buffer)
  @dead = false
end

Instance Method Details

#finalizeObject



28
29
30
31
32
33
# File 'lib/schlepp/sink/filter/compressor/stream.rb', line 28

def finalize
  if !@dead
    @compressor.close
    @dead = true
  end
end

#lengthObject



21
22
23
24
25
26
# File 'lib/schlepp/sink/filter/compressor/stream.rb', line 21

def length
  if @dead
    raise "Stream has been dumped. No more writing permitted."
  end
  @compressor.pos
end

#to_sObject



35
36
37
38
# File 'lib/schlepp/sink/filter/compressor/stream.rb', line 35

def to_s
  finalize
  @buffer.string
end

#write(data) ⇒ Object



14
15
16
17
18
19
# File 'lib/schlepp/sink/filter/compressor/stream.rb', line 14

def write(data)
  if @dead
    raise "Stream has been dumped. No more writing permitted."
  end
  @compressor << data
end