Adopted removal of alignedBytes() in other code.

This commit is contained in:
Timofey Solomko
2016-12-09 01:08:49 +03:00
parent 0a50b5d10f
commit 78fd83dda2
2 changed files with 9 additions and 7 deletions
+4 -2
View File
@@ -69,8 +69,10 @@ public class Deflate: DecompressionAlgorithm {
guard length & nlength == 0 else { throw DeflateError.WrongBlockLengths }
// Process uncompressed data into the output
// TODO: Replace precondition with guard and error throwing.
precondition(pointerData.bitShift == 0, "Misaligned byte.")
out.append(contentsOf: pointerData.alignedBytes(count: length))
precondition(pointerData.bitMask == 1, "Misaligned byte.")
for _ in 0..<length {
out.append(pointerData.alignedByte())
}
} else if blockType == [1, 0] || blockType == [0, 1] {
// Block with Huffman coding (either static or dynamic)
+5 -5
View File
@@ -38,10 +38,10 @@ public class GzipArchive: Archive {
struct ServiceInfo: Equatable {
let magic: [UInt8]
let magic: Int
let method: UInt8
let flags: UInt8
let mtime: [UInt8]
let mtime: Int
let extraFlags: UInt8
let osType: UInt8
// Optional fields
@@ -64,8 +64,8 @@ public class GzipArchive: Archive {
static func serviceInfo(pointerData: DataWithPointer) throws -> ServiceInfo {
// First two bytes should be correct 'magic' bytes
let magic = pointerData.alignedBytes(count: 2)
guard magic == [31, 139] else { throw GzipError.WrongMagic }
let magic = pointerData.intFromBits(count: 16)
guard magic == 0x1f8b else { throw GzipError.WrongMagic }
// Third byte is a method of compression. Only type 8 (DEFLATE) compression is supported
let method = pointerData.alignedByte()
@@ -75,7 +75,7 @@ public class GzipArchive: Archive {
var serviceInfo = ServiceInfo(magic: magic,
method: method,
flags: pointerData.alignedByte(),
mtime: pointerData.alignedBytes(count: 4),
mtime: pointerData.intFromBits(count: 32),
extraFlags: pointerData.alignedByte(),
osType: pointerData.alignedByte(),
fileName: "", comment: "", crc: 0)