Use new int(fromBytes:) function

This commit is contained in:
Timofey Solomko
2018-04-10 22:37:16 +03:00
parent 1452f685cb
commit 05852b179b
8 changed files with 18 additions and 28 deletions
+2 -2
View File
@@ -218,8 +218,8 @@ public class SevenZipContainer: Container {
let startHeaderCRC = bitReader.uint32()
/// - Note: Relative to SignatureHeader
let nextHeaderOffset = bitReader.uint64().toInt()
let nextHeaderSize = bitReader.uint64().toInt()
let nextHeaderOffset = bitReader.int(fromBytes: 8)
let nextHeaderSize = bitReader.int(fromBytes: 8)
let nextHeaderCRC = bitReader.uint32()
bitReader.offset = 12
+1 -1
View File
@@ -29,7 +29,7 @@ public class LZMA: DecompressionAlgorithm {
try decoder.setProperties(byteReader.byte())
decoder.resetStateAndDecoders()
decoder.dictionarySize = byteReader.uint32().toInt()
decoder.dictionarySize = byteReader.int(fromBytes: 4)
let uncompSize = uncompressedSize ?? byteReader.uint64()
if uncompSize == UInt64.max {
+2 -2
View File
@@ -160,8 +160,8 @@ public class XZArchive: Archive {
_ byteReader: ByteReader) throws {
let footerCRC = byteReader.uint32()
/// Indicates the size of Index field. Should match its real size.
let backwardSize = (byteReader.uint32().toInt() + 1) * 4
let streamFooterFlags = byteReader.uint16().toInt()
let backwardSize = (byteReader.int(fromBytes: 4) + 1) * 4
let streamFooterFlags = byteReader.int(fromBytes: 2)
byteReader.offset -= 6
guard CheckSums.crc32(byteReader.bytes(count: 6)) == footerCRC
+4 -14
View File
@@ -84,8 +84,8 @@ struct InfoZipUnixExtraField: ZipExtraField {
case .centralDirectory:
return nil
case .localHeader:
self.uid = byteReader.uint16().toInt()
self.gid = byteReader.uint16().toInt()
self.uid = byteReader.int(fromBytes: 2)
self.gid = byteReader.int(fromBytes: 2)
}
}
@@ -111,24 +111,14 @@ struct InfoZipNewUnixExtraField: ZipExtraField {
if uidSize > 8 {
byteReader.offset += uidSize
} else {
var uid = 0
for i in 0..<uidSize {
let byte = byteReader.byte()
uid |= byte.toInt() << (8 * i)
}
self.uid = uid
self.uid = byteReader.int(fromBytes: uidSize)
}
let gidSize = byteReader.byte().toInt()
if gidSize > 8 {
byteReader.offset += gidSize
} else {
var gid = 0
for i in 0..<gidSize {
let byte = byteReader.byte()
gid |= byte.toInt() << (8 * i)
}
self.gid = gid
self.gid = byteReader.int(fromBytes: gidSize)
}
}
+4 -4
View File
@@ -64,9 +64,9 @@ struct ZipCentralDirectoryEntry {
self.compSize = UInt64(truncatingIfNeeded: byteReader.uint32())
self.uncompSize = UInt64(truncatingIfNeeded: byteReader.uint32())
let fileNameLength = byteReader.uint16().toInt()
let extraFieldLength = byteReader.uint16().toInt()
let fileCommentLength = byteReader.uint16().toInt()
let fileNameLength = byteReader.int(fromBytes: 2)
let extraFieldLength = byteReader.int(fromBytes: 2)
let fileCommentLength = byteReader.int(fromBytes: 2)
self.diskNumberStart = UInt32(truncatingIfNeeded: byteReader.uint16())
@@ -84,7 +84,7 @@ struct ZipCentralDirectoryEntry {
while byteReader.offset - extraFieldStart < extraFieldLength {
// There are a lot of possible extra fields.
let headerID = byteReader.uint16()
let size = byteReader.uint16().toInt()
let size = byteReader.int(fromBytes: 2)
switch headerID {
case 0x0001: // Zip64
// Zip64 extra field is a special case, because it requires knowledge about central directory fields.
+1 -1
View File
@@ -166,7 +166,7 @@ public class ZipContainer: Container {
// But first, we should check for "Archive extra data record" and skip it if present.
byteReader.offset = endOfCD.cdOffset.toInt()
if byteReader.uint32() == 0x08064b50 {
byteReader.offset += byteReader.uint32().toInt()
byteReader.offset += byteReader.int(fromBytes: 4)
} else {
byteReader.offset -= 4
}
+1 -1
View File
@@ -40,7 +40,7 @@ struct ZipEndOfCentralDirectory {
// There is also a .ZIP file comment, but we don't need it.
// Here's how it can be processed:
// let zipCommentLength = byteReader.uint16().toInt()
// let zipCommentLength = byteReader.int(fromBytes: 2)
// let zipComment = String(data: Data(bytes: byteReader.bytes(count: zipCommentLength)),
// encoding: .utf8)
+3 -3
View File
@@ -58,8 +58,8 @@ struct ZipLocalHeader {
self.compSize = UInt64(truncatingIfNeeded: byteReader.uint32())
self.uncompSize = UInt64(truncatingIfNeeded: byteReader.uint32())
let fileNameLength = byteReader.uint16().toInt()
let extraFieldLength = byteReader.uint16().toInt()
let fileNameLength = byteReader.int(fromBytes: 2)
let extraFieldLength = byteReader.int(fromBytes: 2)
guard let fileName = byteReader.getZipStringField(fileNameLength, useUtf8)
else { throw ZipError.wrongTextField }
@@ -70,7 +70,7 @@ struct ZipLocalHeader {
while byteReader.offset - extraFieldStart < extraFieldLength {
// There are a lot of possible extra fields.
let headerID = byteReader.uint16()
let size = byteReader.uint16().toInt()
let size = byteReader.int(fromBytes: 2)
switch headerID {
case 0x0001: // Zip64
// Zip64 extra field is a special case, because it requires knowledge about local header fields,