mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
Replace the usage of the deprecated Data(bytes:) initializer
This commit is contained in:
@@ -97,7 +97,7 @@ public class SevenZipContainer: Container {
|
||||
}
|
||||
|
||||
// Load the stream.
|
||||
let streamData = Data(bytes: byteReader.bytes(count: packInfo.packSizes[streamIndex]))
|
||||
let streamData = Data(byteReader.bytes(count: packInfo.packSizes[streamIndex]))
|
||||
|
||||
// Check stream's CRC, if it's available.
|
||||
if streamIndex < packInfo.digests.count,
|
||||
@@ -122,7 +122,7 @@ public class SevenZipContainer: Container {
|
||||
// Check, if we aren't about to read too much from a stream.
|
||||
guard fileSize <= unpackedStreamData.bytesLeft
|
||||
else { throw SevenZipError.internalStructureError }
|
||||
let fileData = Data(bytes: unpackedStreamData.bytes(count: fileSize))
|
||||
let fileData = Data(unpackedStreamData.bytes(count: fileSize))
|
||||
|
||||
let calculatedFileCRC = CheckSums.crc32(fileData)
|
||||
if nonEmptyFileIndex < substreamInfo.digests.count {
|
||||
|
||||
@@ -218,7 +218,7 @@ public class BZip2: DecompressionAlgorithm {
|
||||
}
|
||||
}
|
||||
|
||||
return Data(bytes: out)
|
||||
return Data(out)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ final class DeltaFilter {
|
||||
}
|
||||
}
|
||||
|
||||
return Data(bytes: out)
|
||||
return Data(out)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public class Deflate: DecompressionAlgorithm {
|
||||
}
|
||||
}
|
||||
|
||||
return Data(bytes: out)
|
||||
return Data(out)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class GzipArchive: Archive {
|
||||
headerBytes.append(2) // Extra flags; 2 means that DEFLATE used slowest algorithm.
|
||||
headerBytes.append(os)
|
||||
|
||||
var outData = Data(bytes: headerBytes)
|
||||
var outData = Data(headerBytes)
|
||||
|
||||
outData.append(fileNameData)
|
||||
outData.append(commentData)
|
||||
@@ -189,14 +189,14 @@ public class GzipArchive: Archive {
|
||||
for i: UInt32 in 0..<4 {
|
||||
crcBytes.append(UInt8(truncatingIfNeeded: (crc32 & (0xFF << (i * 8))) >> (i * 8)))
|
||||
}
|
||||
outData.append(Data(bytes: crcBytes))
|
||||
outData.append(Data(crcBytes))
|
||||
|
||||
let isize = UInt64(data.count) % UInt64(1) << 32
|
||||
var isizeBytes = [UInt8]()
|
||||
for i: UInt64 in 0..<4 {
|
||||
isizeBytes.append(UInt8(truncatingIfNeeded: (isize & (0xFF << (i * 8))) >> (i * 8)))
|
||||
}
|
||||
outData.append(Data(bytes: isizeBytes))
|
||||
outData.append(Data(isizeBytes))
|
||||
|
||||
return outData
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class LZMA: DecompressionAlgorithm {
|
||||
decoder.uncompressedSize = uncompSize ?? -1
|
||||
|
||||
try decoder.decode()
|
||||
return Data(bytes: decoder.out)
|
||||
return Data(decoder.out)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class LZMA2: DecompressionAlgorithm {
|
||||
static func decompress(_ byteReader: ByteReader, _ dictSizeByte: UInt8) throws -> Data {
|
||||
let decoder = try LZMA2Decoder(byteReader, dictSizeByte)
|
||||
try decoder.decode()
|
||||
return Data(bytes: decoder.out)
|
||||
return Data(decoder.out)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ public struct TarEntryInfo: ContainerEntryInfo {
|
||||
// It determines the end of the actual prefix and the beginning of the updated name field.
|
||||
#if (swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))) || !os(Linux)
|
||||
let lastPrefixSlashIndex = nameData.prefix(upTo: maxPrefixLength)
|
||||
.range(of: Data(bytes: [0x2f]), options: .backwards)?.lowerBound ?? -1
|
||||
.range(of: Data([0x2f]), options: .backwards)?.lowerBound ?? -1
|
||||
#else
|
||||
// TODO: This is a workaround for runtime crash in `Data.prefix(upTo:).range(of:options:)` on Linux with
|
||||
// Swift 4.1. It seems like it is fixed in 4.2 and master snapshots, so it will be removed when Swift
|
||||
@@ -480,7 +480,7 @@ fileprivate extension Data {
|
||||
value >>= 8
|
||||
}
|
||||
buffer[0] |= 0x80 // Highest bit indicates base-256 encoding.
|
||||
self.append(Data(bytes: buffer))
|
||||
self.append(Data(buffer))
|
||||
}
|
||||
|
||||
mutating func append(tarString string: String?, maxLength: Int) throws {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ZipContainer: Container {
|
||||
byteReader.offset = helper.dataOffset
|
||||
switch helper.entryInfo.compressionMethod {
|
||||
case .copy:
|
||||
fileData = Data(bytes: byteReader.bytes(count: uncompSize.toInt()))
|
||||
fileData = Data(byteReader.bytes(count: uncompSize.toInt()))
|
||||
case .deflate:
|
||||
let bitReader = LsbBitReader(byteReader)
|
||||
fileData = try Deflate.decompress(bitReader)
|
||||
|
||||
@@ -41,7 +41,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.int(fromBytes: 2)
|
||||
// let zipComment = String(data: Data(bytes: byteReader.bytes(count: zipCommentLength)),
|
||||
// let zipComment = String(data: Data(byteReader.bytes(count: zipCommentLength)),
|
||||
// encoding: .utf8)
|
||||
|
||||
// Check if zip64 records are present.
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ZlibArchive: Archive {
|
||||
120, // CM (Compression Method) = 8 (DEFLATE), CINFO (Compression Info) = 7 (32K window size).
|
||||
218 // Flags: slowest algorithm, no preset dictionary.
|
||||
]
|
||||
var outData = Data(bytes: out)
|
||||
var outData = Data(out)
|
||||
outData.append(Deflate.compress(data: data))
|
||||
|
||||
let adler32 = CheckSums.adler32(data)
|
||||
@@ -61,7 +61,7 @@ public class ZlibArchive: Archive {
|
||||
for i in 0..<4 {
|
||||
adlerBytes.append(UInt8(truncatingIfNeeded: (adler32 & (0xFF << ((3 - i) * 8))) >> ((3 - i) * 8)))
|
||||
}
|
||||
outData.append(Data(bytes: adlerBytes))
|
||||
outData.append(Data(adlerBytes))
|
||||
|
||||
return outData
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ struct TestZipExtraField: ZipExtraField {
|
||||
init(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) {
|
||||
self.size = size
|
||||
self.location = location
|
||||
self.helloString = String(data: Data(bytes: byteReader.bytes(count: size)), encoding: .utf8)
|
||||
self.helloString = String(data: Data(byteReader.bytes(count: size)), encoding: .utf8)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user