Sha256: a416ce77706929c3be898c6d87722918416df987cd3d22facfbe915c2d823b03

Contents?: true

Size: 730 Bytes

Versions: 15

Compression:

Stored size: 730 Bytes

Contents

require "zlib"
module RocketJob
  module Sliced
    # Compress the records within a slice
    class CompressedSlice < ::RocketJob::Sliced::Slice
      private

      def parse_records
        records = attributes.delete("records")

        # Convert BSON::Binary to a string
        binary_str = records.data

        str      = Zlib::Inflate.inflate(binary_str)
        @records = Hash.from_bson(BSON::ByteBuffer.new(str))["r"]
      end

      def serialize_records
        return [] if @records.nil? || @records.empty?

        # Convert slice of records into a single string
        str = {"r" => records.to_a}.to_bson.to_s

        data = Zlib::Deflate.deflate(str)
        BSON::Binary.new(data)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rocketjob-6.0.0.rc3 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.0.0.rc2 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.0.0.rc1 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.4.1 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.4.0 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.4.0.beta2 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.4.0.beta1 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.3.3 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.3.2 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.3.1 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.3.0 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.2.0 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.2.0.beta3 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.2.0.beta2 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-5.2.0.beta1 lib/rocket_job/sliced/compressed_slice.rb