Skip to content

Commit

Permalink
Replace usages of CRC32 in std-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardiff committed Mar 6, 2020
1 parent b7fe4f5 commit 540e992
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/gzip/gzip.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "flate"
require "crc32"
require "digest/crc32"

# The Gzip module contains readers and writers of gzip format compressed
# data, as specified in [RFC 1952](https://www.ietf.org/rfc/rfc1952.txt).
Expand Down
6 changes: 3 additions & 3 deletions src/gzip/reader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Gzip::Reader < IO
# Creates a new reader from the given *io*.
def initialize(@io : IO, @sync_close = false)
# CRC32 of written data
@crc32 = CRC32.initial
@crc32 = Digest::CRC32.initial

# Total size of the original (uncompressed) input data modulo 2^32.
@isize = 0_u32
Expand Down Expand Up @@ -101,7 +101,7 @@ class Gzip::Reader < IO
end

# Reset checksum and total size for next entry
@crc32 = CRC32.initial
@crc32 = Digest::CRC32.initial
@isize = 0_u32

# Check if another header with data comes
Expand All @@ -115,7 +115,7 @@ class Gzip::Reader < IO
end
else
# Update CRC32 and total data size
@crc32 = CRC32.update(slice[0, read_bytes], @crc32)
@crc32 = Digest::CRC32.update(slice[0, read_bytes], @crc32)

# Using wrapping addition here because isize is only 32 bits wide but
# uncompressed data size can be bigger.
Expand Down
4 changes: 2 additions & 2 deletions src/gzip/writer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Gzip::Writer < IO
# Creates a new writer to the given *io*.
def initialize(@io : IO, @level = Gzip::DEFAULT_COMPRESSION, @sync_close = false)
# CRC32 of written data
@crc32 = CRC32.initial
@crc32 = Digest::CRC32.initial

# Total size of the original (uncompressed) input data modulo 2^32.
@isize = 0
Expand Down Expand Up @@ -77,7 +77,7 @@ class Gzip::Writer < IO
flate_io.write(slice)

# Update CRC32 and total data size
@crc32 = CRC32.update(slice, @crc32)
@crc32 = Digest::CRC32.update(slice, @crc32)

# Using wrapping addition here because isize is only 32 bits wide but
# uncompressed data size can be bigger.
Expand Down
2 changes: 1 addition & 1 deletion src/zip/zip.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "flate"
require "crc32"
require "digest/crc32"
require "./*"

# The Zip module contains readers and writers of the zip
Expand Down

0 comments on commit 540e992

Please sign in to comment.