Sha256: 53d5a3294b1d2b084c154f0b6c9aab5f9eeb89847b61f87ed74b13b37985d574

Contents?: true

Size: 741 Bytes

Versions: 9

Compression:

Stored size: 741 Bytes

Contents

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

      def parse_records
        # Convert BSON::Binary to a string
        compressed_str   = attributes.delete("records").data
        decompressed_str = Zlib::Inflate.inflate(compressed_str)
        @records         = Hash.from_bson(BSON::ByteBuffer.new(decompressed_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

9 entries across 9 versions & 1 rubygems

Version Path
rocketjob-6.3.1 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.3.0 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.2.0 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.1.1 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.1.0 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.0.3 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.0.2 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.0.1 lib/rocket_job/sliced/compressed_slice.rb
rocketjob-6.0.0 lib/rocket_job/sliced/compressed_slice.rb