Class: Bzip2::Writer
- Inherits:
-
Data
- Object
- Data
- Bzip2::Writer
- Defined in:
- lib/bzip2/writer.rb,
ext/bzip2/bzip2.c
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
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(data) ⇒ Object
Append some data to this buffer, returning the buffer so this method can be chained.
- #close ⇒ Object
- #close! ⇒ Object
- #closed? ⇒ Boolean (also: #closed)
- #flush ⇒ Object (also: #finish)
- #initialize ⇒ Object constructor
-
#print(*objs) ⇒ Object
Similar to Bzip2::Writer#puts except a newline is not appended after each object appended to this buffer.
-
#printf(format, *ojbs) ⇒ Object
Prints data to this buffer with the specified format.
- #putc ⇒ Object
-
#puts(*objs) ⇒ Object
Adds a number of strings to this buffer.
-
#to_io ⇒ File, String
Returns the io stream underlying this stream.
- #write ⇒ Object
Constructor Details
#initialize ⇒ Object
Class Method Details
.allocate ⇒ Object
.open ⇒ Object
Instance Method Details
#<<(data) ⇒ Object
41 42 |
# File 'lib/bzip2/writer.rb', line 41 def << data end |
#close ⇒ Object
#close! ⇒ Object
#closed? ⇒ Boolean Also known as: closed
#flush ⇒ Object Also known as: finish
#print(*objs) ⇒ Object
Similar to Bzip2::Writer#puts except a newline is not appended after each object appended to this buffer
54 55 |
# File 'lib/bzip2/writer.rb', line 54 def print *objs end |
#printf(format, *ojbs) ⇒ Object
Prints data to this buffer with the specified format.
60 61 |
# File 'lib/bzip2/writer.rb', line 60 def printf format, *ojbs end |
#putc ⇒ Object
#puts(*objs) ⇒ Object
Adds a number of strings to this buffer. A newline is also inserted into the buffer after each object
47 48 |
# File 'lib/bzip2/writer.rb', line 47 def puts *objs end |
#to_io ⇒ File, String
Returns the io stream underlying this stream. If the strem was constructed with a file, that is returned. Otherwise, an empty string is returned.
76 77 78 79 80 81 |
# File 'ext/bzip2/bzip2.c', line 76
VALUE bz_to_io(VALUE obj) {
struct bz_file *bzf;
Get_BZ2(obj, bzf);
return bzf->io;
}
|