(Swift) Split File into Chunks
Demonstrates how to split a file into chunks.
func chilkatTest() {
let fac = CkoFileAccess()!
// Any type of file may be split. It doesn't matter if it's
// a binary file or a text file.
var fileToSplit: String? = "qa_data/hamlet.xml"
var partPrefix: String? = "hamlet"
var partExtension: String? = "part"
var maxChunkSize: Int = 50000
var destDirPath: String? = "qa_output"
// Splits hamlet.xml into hamlet1.part, hamlet2.part, ...
// Output files are written to the current working directory.
// Each chunk will be 50000 bytes except for the last which
// will be the remainder.
var success: Bool = fac.splitFile(fileToSplit, partPrefix: partPrefix, partExtension: partExtension, partSize: maxChunkSize, destDir: destDirPath)
if success == true {
print("Success.")
}
else {
print("\(fac.lastErrorText!)")
}
}
|