From 0571f19bdbce008c2c969a4e74664ba6d082aabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Mon, 8 Jul 2024 21:19:49 +0200 Subject: [PATCH] Add spec for `Compress::Gzip::Writer` with `extra` (#14788) --- spec/std/compress/gzip/gzip_spec.cr | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/std/compress/gzip/gzip_spec.cr b/spec/std/compress/gzip/gzip_spec.cr index 8ffa0624bc6d..675b704436ea 100644 --- a/spec/std/compress/gzip/gzip_spec.cr +++ b/spec/std/compress/gzip/gzip_spec.cr @@ -71,4 +71,27 @@ describe Compress::Gzip do end end end + + it "writes and reads file with extra fields" do + io = IO::Memory.new + Compress::Gzip::Writer.open(io) do |gzip| + header = gzip.header + header.modification_time = Time.utc(2012, 9, 4, 22, 6, 5) + header.os = 3_u8 + header.extra = Bytes[1, 2, 3, 4, 5] + header.name = "test.txt" + header.comment = "happy birthday" + gzip << "One\nTwo" + end + io.rewind + Compress::Gzip::Reader.open(io) do |gzip| + header = gzip.header.not_nil! + header.modification_time.to_utc.should eq(Time.utc(2012, 9, 4, 22, 6, 5)) + header.os.should eq(3_u8) + header.extra.should eq(Bytes[1, 2, 3, 4, 5]) + header.name.should eq("test.txt") + header.comment.should eq("happy birthday") + gzip.gets_to_end.should eq("One\nTwo") + end + end end