[openstreetmap/openstreetmap-website] Compress plain GPX uploads with gzip (PR #7124)
Tom Hughes
notifications at github.com
Sun Jun 28 10:38:49 UTC 2026
@tomhughes commented on this pull request.
The third commit should probably be squashed into the first one?
> + # Gzip plain GPX before S3 to save storage.
+ gz = Tempfile.new(["trace", ".gpx.gz"])
+ gz.binmode
+
+ writer = Zlib::GzipWriter.new(gz)
+ File.open(attachable.path, "rb") { |source| IO.copy_stream(source, writer) }
+ writer.finish
+ gz.rewind
+ # Delete the temp file from disk now, but keep gz open. Active Storage still
+ # reads this open handle to upload on save same as xml_file.
+ gz.unlink
I really don't like this, and like @pablobm would much prefer to use a block (which actually needs `Tempfile.create` not `Tempfile.new`) but as you say that doesn't really work here.
It's a shame ruby doesn't just unlink at the end of the block in that case but return a handle to a still open file but I guess that may not be very portable to all the platforms it needs to support.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/7124#pullrequestreview-4587403666
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/7124/review/4587403666 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260628/2495916a/attachment.htm>
More information about the rails-dev
mailing list