Class | Bzip2::Writer |
In: |
lib/bzip2/writer.rb
ext/bzip2.c |
Parent: | Object |
flush | -> | finish |
@param [File] io the file which to write compressed data to
Creates a new Bzip2::Writer for compressing a stream of data. An optional io object (something responding to write) can be supplied which data will be written to.
If nothing is given, the Bzip2::Writer#flush method can be called to retrieve the compressed stream so far.
writer = Bzip2::Writer.new File.open('files.bz2') writer << 'a' writer << 'b' writer.close writer = Bzip2::Writer.new writer << 'abcde' writer.flush # => 'abcde' compressed
@param [String] filename the name of the file to write to @param [String] mode a mode string passed to Kernel#open @yieldparam [Bzip2::Writer] writer the Bzip2::Writer instance
If a block is given, the created Bzip2::Writer instance is yielded to the block and will be closed when the block completes. It is guaranteed via ensure that the writer is closed
If a block is not given, a Bzip2::Writer instance will be returned
Bzip2::Writer.open('file') { |f| f << data } writer = Bzip2::Writer.open('file') writer << data writer.close
@return [Bzip2::Writer, nil]
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
@param [to_s] data anything responding to to_s @see IO#<<
Closes this writer for further use. The remaining data is compressed and flushed.
If the writer was constructed with an io object, that object is returned. Otherwise, the actual compressed data is returned
writer = Bzip2::Writer.new File.open('path', 'w') writer << 'a' writer.close # => #<File:path> writer = Bzip2::Writer.new writer << 'a' writer.close # => "BZh91AY&SY...
Flushes all of the data in this stream to the underlying IO.
If this writer was constructed with no underlying io object, the compressed data is returned as a string.
@return [String, nil] @raise [IOError] if the stream has been closed
Similar to Bzip2::Writer#puts except a newline is not appended after each object appended to this buffer
@see IO#print
Write one byte into this stream. @param [Integer] num the number value of the character to write @return [Integer] always 1 @raise [IOError] if the stream has been closed
Adds a number of strings to this buffer. A newline is also inserted into the buffer after each object @see IO#puts
Returns the io stream underlying this stream. If the strem was constructed with a file, that is returned. Otherwise, an empty string is returned.
@return [File, String] similar to whatever the stream was constructed with @raise [IOError] if the stream has been closed
@param [String] data the data to write @return [Integer] the length of the data which was written (uncompressed) @raise [IOError] if the stream has been closed