Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yockow/swifttemporaryfile
SwiftTemporaryFile provides functions related to temporary files.
https://github.com/yockow/swifttemporaryfile
Last synced: 24 days ago
JSON representation
SwiftTemporaryFile provides functions related to temporary files.
- Host: GitHub
- URL: https://github.com/yockow/swifttemporaryfile
- Owner: YOCKOW
- License: mit
- Created: 2018-09-11T07:25:42.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2023-09-22T09:12:58.000Z (about 1 year ago)
- Last Synced: 2023-09-23T06:51:10.724Z (about 1 year ago)
- Language: Swift
- Homepage:
- Size: 98.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# What is `SwiftTemporaryFile`?
`SwiftTemporaryFile` provides functions related to temporary files.
It was originally written as a part of [SwiftCGIResponder](https://github.com/YOCKOW/SwiftCGIResponder).# Requirements
- Swift 5, 6
- macOS(>=10.15) or Linux## Dependencies
![Dependencies](./dependencies.svg)
# Usage
```Swift
import Foundation
import TemporaryFilelet 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.
*/
``````Swift
import TemporaryFile// You can pass a closure:
TemporaryFile { (tmpFile: TemporaryFile) -> Void in
try! tmpFile.write(contentsOf: "Hello, World!".data(using:.utf8)!)
// ...
} // Automatically closed.
```# License
MIT License.
See "LICENSE.txt" for more information.