class RocketJob::Sliced::BZip2OutputSlice

This is a specialized output serializer that renders each output slice as a single BZip2 compressed stream. BZip2 allows multiple output streams to be written into a single BZip2 file.

Notes:

Public Class Methods

binary_format() click to toggle source

This is a specialized binary slice for creating BZip2 binary data from each slice that must be downloaded as-is into output files.

# File lib/rocket_job/sliced/bzip2_output_slice.rb, line 13
def self.binary_format
  :bz2
end
to_binary(records, record_delimiter = "\n") click to toggle source

Compress the supplied records with BZip2

# File lib/rocket_job/sliced/bzip2_output_slice.rb, line 18
def self.to_binary(records, record_delimiter = "\n")
  return [] if records.blank?

  lines = Array(records).join(record_delimiter) + record_delimiter
  s     = StringIO.new
  IOStreams::Bzip2::Writer.stream(s) { |io| io.write(lines) }
  s.string
end

Private Instance Methods

parse_records() click to toggle source

Returns [Hash] the BZip2 compressed binary data in binary form when reading back from Mongo.

# File lib/rocket_job/sliced/bzip2_output_slice.rb, line 30
def parse_records
  # Convert BSON::Binary to a string
  @records = [attributes.delete("records").data]
end
serialize_records() click to toggle source

Returns [BSON::Binary] the records compressed using BZip2 into a string.

# File lib/rocket_job/sliced/bzip2_output_slice.rb, line 36
def serialize_records
  # TODO: Make the line terminator configurable
  BSON::Binary.new(self.class.to_binary(@records))
end