Files
SWCompression/Sources/swcomp/XZCommand.swift
T
2017-10-21 23:22:40 +03:00

27 lines
746 B
Swift

// Copyright (c) 2017 Timofey Solomko
// Licensed under MIT License
//
// See LICENSE for license information
import Foundation
import SWCompression
import SwiftCLI
class XZCommand: Command {
let name = "xz"
let shortDescription = "Extracts XZ archive"
let archive = Parameter()
let outputPath = OptionalParameter()
func execute() throws {
let fileData = try Data(contentsOf: URL(fileURLWithPath: self.archive.value),
options: .mappedIfSafe)
let outputPath = self.outputPath.value ?? FileManager.default.currentDirectoryPath
let decompressedData = try XZArchive.unarchive(archive: fileData)
try decompressedData.write(to: URL(fileURLWithPath: outputPath))
}
}