Replace the usage of the deprecated Data(bytes:) initializer

This commit is contained in:
Timofey Solomko
2019-05-01 19:30:48 +03:00
parent e329e0c2aa
commit db82490ed8
12 changed files with 17 additions and 17 deletions
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -218,7 +218,7 @@ public class BZip2: DecompressionAlgorithm {
}
}
return Data(bytes: out)
return Data(out)
}
}
+1 -1
View File
@@ -29,7 +29,7 @@ final class DeltaFilter {
}
}
return Data(bytes: out)
return Data(out)
}
}
+1 -1
View File
@@ -203,7 +203,7 @@ public class Deflate: DecompressionAlgorithm {
}
}
return Data(bytes: out)
return Data(out)
}
}
+3 -3
View File
@@ -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
}
+1 -1
View File
@@ -65,7 +65,7 @@ public class LZMA: DecompressionAlgorithm {
decoder.uncompressedSize = uncompSize ?? -1
try decoder.decode()
return Data(bytes: decoder.out)
return Data(decoder.out)
}
}
+1 -1
View File
@@ -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)
}
}
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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.
+2 -2
View File
@@ -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
}
+1 -1
View File
@@ -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)
}
}