Class: Bzip2::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/bzip2/writer.rb

Overview

A Bzip2::Writer represents a stream which compresses data written to it. It can be constructed with another IO object (a File) which data can be written to. Otherwise, data is all stored internally as a string and can be retrieved via the Bzip2::Writer#flush method

It can both write to files:

writer = Bzip2::Writer.open('file')
writer << data
writer.close

Bzip2::Writer.open('file'){ |f| f << data }

writer = Bzip2::Writer.new File.open('file')

And output data as a string

writer = Bzip2::Writer.new
writer << data
writer.flush # => data compressed via bz2

See Also:

  • The initialize method for examples

Instance Method Summary collapse

Instance Method Details

#<<(data) ⇒ Object

Append some data to this buffer, returning the buffer so this method can be chained

writer = Bzip2::Writer.new
writer << 'asdf' << 1 << obj << 'a'
writer.flush

Parameters:

  • data (#to_s)

    anything responding to #to_s

See Also:

  • IO#<<


40
41
# File 'lib/bzip2/writer.rb', line 40

def << data
end

Similar to Bzip2::Writer#puts except a newline is not appended after each object appended to this buffer

See Also:

  • IO#print


53
54
# File 'lib/bzip2/writer.rb', line 53

def print *objs
end

#printf(format, *ojbs) ⇒ Object

Prints data to this buffer with the specified format.

See Also:

  • Kernel#sprintf


59
60
# File 'lib/bzip2/writer.rb', line 59

def printf format, *ojbs
end

#puts(*objs) ⇒ Object

Adds a number of strings to this buffer. A newline is also inserted into the buffer after each object

See Also:

  • IO#puts


46
47
# File 'lib/bzip2/writer.rb', line 46

def puts *objs
end