Sha256: 686c20e961ff3d71c2b9c6f3218822961cf7679c4a853e68d1675c933b390f90

Contents?: true

Size: 824 Bytes

Versions: 2

Compression:

Stored size: 824 Bytes

Contents

module IOStreams
  module Bzip2
    class Writer
      # Write to a file / stream, compressing with Bzip2
      def self.open(file_name_or_io, _=nil, &block)
        begin
          require 'rbzip2' unless defined?(RBzip2)
        rescue LoadError => e
          raise(LoadError, "Please install the 'rbzip2' gem for Bzip2 streaming support. #{e.message}")
        end

        if IOStreams.reader_stream?(file_name_or_io)
          begin
            io = RBzip2.default_adapter::Compressor.new(file_name_or_io)
            block.call(io)
          ensure
            io.close
          end
        else
          ::File.open(file_name_or_io, 'wb') do |file|
            io = RBzip2.default_adapter::Compressor.new(file)
            block.call(io)
            io.close
          end
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iostreams-0.15.0 lib/io_streams/bzip2/writer.rb
iostreams-0.14.0 lib/io_streams/bzip2/writer.rb