SwiftTemporaryFile
?SwiftTemporaryFile
provides functions related to temporary files.
It was originally written as a part of SwiftCGIResponder.
import Foundation
import TemporaryFile
let tmpFile = TemporaryFile()
try! tmpFile.write(contentsOf: "Hello, World!".data(using:.utf8)!)
try! tmpFile.seek(toOffset: 0)
print(String(data: try! tmpFile.readToEnd()!, encoding: .utf8)!) // Prints "Hello, World!"
try! tmpFile.copy(to: URL(fileURLWithPath: "/my/directory/hello.txt"))
/*
You can explicitly close the temporary file by calling `try tmpFile.close()`,
though all of the temporary files are automatically closed at the end of program.
*/
import TemporaryFile
// You can pass a closure:
TemporaryFile { (tmpFile: TemporaryFile) -> Void in
try! tmpFile.write(contentsOf: "Hello, World!".data(using:.utf8)!)
// ...
} // Automatically closed.
MIT License.
See "LICENSE.txt" for more information.
link |
Stars: 0 |
Last commit: 30 weeks ago |
Full Changelog: https://github.com/YOCKOW/SwiftTemporaryFile/compare/4.0.6...4.0.7
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics