Ruby - prevent GzipWriter from adding metadata onto its header

Pauline

I need to encode a file such that, if the content of the file is the same, then its encoded version is the same too.

The file I need to encode, config.yml, contains the following string:

This is my secret setup file

My code is as follows:

require 'stringio'
require 'base64'
require 'zlib'

my_text = File.read('config.yml')
wio = StringIO.new('W')
w_gz = Zlib::GzipWriter.new(wio)
w_gz.mtime = 0 # Specify the modification time (mtime) in the gzip header
w_gz.orig_name = 'userdata' # Specify the original name (str) in the gzip header
w_gz.write(my_text)
w_gz.close
puts Base64.encode64(wio.string)

At the time when Base64 renders the encoded string, the string must be the exact same if the content of config.yml is the same. However some metadata seems to be added which makes it impossible to get the same Base64-encoded string, example:

First run of the script:

H4sICGoAm1kAA3VzZXJkYXRhAAvJyCxWAKLcSoXi1OSi1BIgVVJaoJCWmZPK BQAdlUQpHQAAAA==

Seconds later:

H4sICG4Am1kAA3VzZXJkYXRhAAvJyCxWAKLcSoXi1OSi1BIgVVJaoJCWmZPK BQAdlUQpHQAAAA==

Minutes later:

H4sICGkBm1kAA3VzZXJkYXRhAAvJyCxWAKLcSoXi1OSi1BIgVVJaoJCWmZPK BQAdlUQpHQAAAA==

tadman

Your attempt to set mtime to 0 seems to be ignored. Using an arbitrary value of 1000000000 or even 1 doesn't cause it to shift.

I think this is because the Gzip library is C-based and 0 is considered false, not assigned, and so is overruled.

The Gzip RFC is pretty short and there's not much metadata in there:

 +---+---+---+---+---+---+---+---+---+---+
 |ID1|ID2|CM |FLG|     MTIME     |XFL|OS | (more-->)
 +---+---+---+---+---+---+---+---+---+---+

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Prevent accordion header from bubbling down a click onto a checkbox in BigCommerce options?

Ruby Prawn PDF Prevent Header Space From Populating Next Page

Adding data from foreach onto existing array

Adding text from mySQL query onto canvas

Prevent Spring's RestTemplate from adding header for each parameters in multipart/form-data

Prevent Javascript adding metadata on File Upload to S3

Prevent Windows Explorer from trying to extract metadata

Prevent Nexus from pulling blocked package metadata

Adding and retrieving metadata from Ember routes

Adding metadata to pdfs in solr from commadn line

Adding metadata to opus file from command line

How to prevent paragraph text from breaking onto next line

Prevent field from adding to savedInstanceBundle

Adding point symbol from subset onto line legend in ggplot

get metadata from a pdf file in ruby

How to prevent dynamically added parent class from adding to its child elements in Angular Material,mat-selection-list?

Displaying a table from MySQL database onto webpage with Ruby Sinatra

Adding Text onto a Rect

Adding view onto an activity

Adding an array onto an array

Strip characters from header in Ruby

How to prevent code for adding an image to ShinyDashboard header appearing in browser tab?

Prevent Microsoft OData Client from requesting Full Metadata

How to prevent Header from rendering on Login screen?

How to prevent HttpClient from sending the Connection header

Prevent TableView header from being highlighted

Prevent Tomcat from sending header "Connection: close"

Prevent images from overlapping a fixed header

Prevent header from getting too small

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive