How to decompress and write data from a .tgz file? #41
-
I am trying to decompress a func uncompressTgzFile(atPath path: String, toDirectory directory: String) throws -> String {
print("uncompressTgzFile called with", path, directory)
let tgzData = try Data(contentsOf: URL(fileURLWithPath: path))
let decompressedData = try! SWCompression.GzipArchive.unarchive(archive: tgzData)
print("uncompressTgzFile decompressedData", decompressedData)
let toFilePath = URL(fileURLWithPath: directory)
try! decompressedData.write(to: toFilePath)
return toFilePath.path
} Here are the params... I am getting the error for the Here is a file you can test with... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The let decompressedData = try! SWCompression.GzipArchive.unarchive(archive: tgzData) you get a TAR archive that has to be further processed with either The error you're seeing is unrelated to the above: you are trying to write a file into an existing path, which is a directory. You have to specify a file name in the URL you are writing to. |
Beta Was this translation helpful? Give feedback.
The
tgz
file is actuallytar.gz
file, which means that this is a TAR archive that was afterwards compressed with GZip. So when you do this:you get a TAR archive that has to be further processed with either
TarContainer.open
orTarReader
.The error you're seeing is unrelated to the above: you are trying to write a file into an existing path, which is a directory. You have to specify a file name in the URL you are writing to.
Data.write(to:)
doesn't automatically append any file names to the path that was provided.