dawarich/app/services/points/raw_data/chunk_compressor.rb

26 lines
626 B
Ruby
Raw Normal View History

2025-12-06 16:43:22 -05:00
# frozen_string_literal: true
module Points
module RawData
class ChunkCompressor
def initialize(points_relation)
@points = points_relation
end
def compress
io = StringIO.new
gz = Zlib::GzipWriter.new(io)
# Stream points to avoid memory issues with large months
@points.select(:id, :raw_data).find_each(batch_size: 1000) do |point|
# Write as JSONL (one JSON object per line)
gz.puts({ id: point.id, raw_data: point.raw_data }.to_json)
end
gz.close
io.string # Returns compressed bytes
end
end
end
end