From 82f150d437124f511115e5e5b2f23ee5e63bdd5d Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Thu, 2 Jan 2020 12:29:24 +0300 Subject: [PATCH] Use LsbBitReader argument in the Gzip and Zlib headers' initializers This fixes issues arising from the removal of _subclass_ relations between bit and byte readers in BBD. --- Sources/GZip/GzipHeader.swift | 28 ++++++++++++++-------------- Sources/Zlib/ZlibHeader.swift | 12 ++++++------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Sources/GZip/GzipHeader.swift b/Sources/GZip/GzipHeader.swift index b5c51463..74401b1e 100644 --- a/Sources/GZip/GzipHeader.swift +++ b/Sources/GZip/GzipHeader.swift @@ -53,23 +53,23 @@ public struct GzipHeader { it might not be archived with GZip at all. */ public init(archive data: Data) throws { - let byteReader = LittleEndianByteReader(data: data) - try self.init(byteReader) + let reader = LsbBitReader(data: data) + try self.init(reader) } - init(_ byteReader: LittleEndianByteReader) throws { + init(_ reader: LsbBitReader) throws { // First two bytes should be correct 'magic' bytes - let magic = byteReader.uint16() + let magic = reader.uint16() guard magic == 0x8b1f else { throw GzipError.wrongMagic } var headerBytes: [UInt8] = [0x1f, 0x8b] // Third byte is a method of compression. Only type 8 (DEFLATE) compression is supported for GZip archives. - let method = byteReader.byte() + let method = reader.byte() guard method == 8 else { throw GzipError.wrongCompressionMethod } headerBytes.append(method) self.compressionMethod = .deflate - let rawFlags = byteReader.byte() + let rawFlags = reader.byte() guard rawFlags & 0xE0 == 0 else { throw GzipError.wrongFlags } let flags = Flags(rawValue: rawFlags) @@ -77,16 +77,16 @@ public struct GzipHeader { var mtime = 0 for i in 0..<4 { - let byte = byteReader.byte() + let byte = reader.byte() mtime |= byte.toInt() << (8 * i) headerBytes.append(byte) } self.modificationTime = mtime == 0 ? nil : Date(timeIntervalSince1970: TimeInterval(mtime)) - let extraFlags = byteReader.byte() + let extraFlags = reader.byte() headerBytes.append(extraFlags) - let rawOsType = byteReader.byte() + let rawOsType = reader.byte() self.osType = FileSystemType(rawOsType) headerBytes.append(rawOsType) @@ -96,12 +96,12 @@ public struct GzipHeader { if flags.contains(.fextra) { var xlen = 0 for i in 0..<2 { - let byte = byteReader.byte() + let byte = reader.byte() xlen |= byte.toInt() << (8 * i) headerBytes.append(byte) } for _ in 0..