mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Replace Int() conversions with toInt() functions
This commit is contained in:
@@ -232,8 +232,8 @@ public class SevenZipContainer: Container {
|
||||
let startHeaderCRC = bitReader.uint32()
|
||||
|
||||
/// - Note: Relative to SignatureHeader
|
||||
let nextHeaderOffset = Int(bitReader.uint64())
|
||||
let nextHeaderSize = Int(bitReader.uint64())
|
||||
let nextHeaderOffset = bitReader.uint64().toInt()
|
||||
let nextHeaderSize = bitReader.uint64().toInt()
|
||||
let nextHeaderCRC = bitReader.uint32()
|
||||
|
||||
bitReader.offset = 12
|
||||
|
||||
@@ -119,15 +119,15 @@ extension Deflate: CompressionAlgorithm {
|
||||
case let .byte(byte):
|
||||
mainLiterals.code(symbol: byte.toInt())
|
||||
case let .lengthDistance(length, distance):
|
||||
let lengthSymbol = Constants.lengthCode[Int(length) - 3]
|
||||
let lengthExtraBits = Int(length) - Constants.lengthBase[lengthSymbol - 257]
|
||||
let lengthSymbol = Constants.lengthCode[length.toInt() - 3]
|
||||
let lengthExtraBits = length.toInt() - Constants.lengthBase[lengthSymbol - 257]
|
||||
let lengthExtraBitsCount = (257 <= lengthSymbol && lengthSymbol <= 260) || lengthSymbol == 285 ?
|
||||
0 : (((lengthSymbol - 257) >> 2) - 1)
|
||||
mainLiterals.code(symbol: lengthSymbol)
|
||||
bitWriter.write(number: lengthExtraBits, bitsCount: lengthExtraBitsCount)
|
||||
|
||||
let distanceSymbol = ((Constants.distanceBase.index { $0 > Int(distance) }) ?? 30) - 1
|
||||
let distanceExtraBits = Int(distance) - Constants.distanceBase[distanceSymbol]
|
||||
let distanceSymbol = ((Constants.distanceBase.index { $0 > distance.toInt() }) ?? 30) - 1
|
||||
let distanceExtraBits = distance.toInt() - Constants.distanceBase[distanceSymbol]
|
||||
let distanceExtraBitsCount = distanceSymbol == 0 || distanceSymbol == 1 ?
|
||||
0 : ((distanceSymbol >> 1) - 1)
|
||||
mainDistances.code(symbol: distanceSymbol)
|
||||
|
||||
@@ -36,7 +36,7 @@ public class LZMA: DecompressionAlgorithm {
|
||||
if uncompSize == UInt64.max {
|
||||
decoder.uncompressedSize = -1
|
||||
} else {
|
||||
decoder.uncompressedSize = Int(truncatingIfNeeded: uncompSize)
|
||||
decoder.uncompressedSize = uncompSize.toInt()
|
||||
}
|
||||
|
||||
try decoder.decode()
|
||||
|
||||
@@ -65,7 +65,7 @@ class LZMARangeDecoder {
|
||||
res = res &+ (t &+ 1)
|
||||
count -= 1
|
||||
} while count > 0
|
||||
return Int(res)
|
||||
return res.toInt()
|
||||
}
|
||||
|
||||
/// Decodes binary symbol (bit) with predicted (estimated) probability.
|
||||
|
||||
@@ -35,7 +35,7 @@ class LZMA2Decoder {
|
||||
dictSize <<= UInt32(bits.toInt() / 2 + 11)
|
||||
}
|
||||
|
||||
self.decoder.dictionarySize = Int(dictSize)
|
||||
self.decoder.dictionarySize = dictSize.toInt()
|
||||
}
|
||||
|
||||
/// Main LZMA2 decoder function.
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ZipContainer: Container {
|
||||
byteReader.offset = info.localHeader.dataOffset
|
||||
switch info.compressionMethod {
|
||||
case .copy:
|
||||
fileData = Data(bytes: byteReader.bytes(count: Int(truncatingIfNeeded: uncompSize)))
|
||||
fileData = Data(bytes: byteReader.bytes(count: uncompSize.toInt()))
|
||||
case .deflate:
|
||||
let bitReader = LsbBitReader(data: byteReader.data)
|
||||
bitReader.offset = byteReader.offset
|
||||
@@ -149,12 +149,12 @@ public class ZipContainer: Container {
|
||||
let cdEntries = endOfCD.cdEntries
|
||||
|
||||
// OK, now we are ready to read Central Directory itself.
|
||||
var entryIndex = Int(truncatingIfNeeded: endOfCD.cdOffset)
|
||||
var entryIndex = endOfCD.cdOffset.toInt()
|
||||
|
||||
// First, check for "Archive extra data record" and skip it if present.
|
||||
byteReader.offset = entryIndex
|
||||
if byteReader.uint32() == 0x08064b50 {
|
||||
entryIndex += Int(truncatingIfNeeded: byteReader.uint32())
|
||||
entryIndex += byteReader.uint32().toInt()
|
||||
}
|
||||
|
||||
for _ in 0..<cdEntries {
|
||||
|
||||
@@ -71,7 +71,7 @@ struct ZipEndOfCentralDirectory {
|
||||
else { throw ZipError.multiVolumesNotSupported }
|
||||
|
||||
// Now we need to move to Zip64 End of CD.
|
||||
byteReader.offset = Int(UInt(truncatingIfNeeded: zip64CDEndOffset))
|
||||
byteReader.offset = zip64CDEndOffset.toInt()
|
||||
|
||||
// Check signature.
|
||||
guard byteReader.uint32() == 0x06064b50
|
||||
|
||||
@@ -82,7 +82,7 @@ public struct ZipEntryInfo: ContainerEntryInfo {
|
||||
let cdEntry = try ZipCentralDirectoryEntry(data, offset)
|
||||
self.cdEntry = cdEntry
|
||||
|
||||
let localHeader = try ZipLocalHeader(data, Int(truncatingIfNeeded: cdEntry.localHeaderOffset))
|
||||
let localHeader = try ZipLocalHeader(data, cdEntry.localHeaderOffset.toInt())
|
||||
try localHeader.validate(with: cdEntry, currentDiskNumber)
|
||||
self.localHeader = localHeader
|
||||
|
||||
|
||||
Reference in New Issue
Block a user