mirror of
https://github.com/xtool-org/xtool.git
synced 2026-02-04 11:53:30 +01:00
- We now have a single tmpdir "root" that can be recreated at launch to clean up old stragglers - The location of this tmpdir root can be controlled by `XTL_TMPDIR` or `TMPDIR`. In general the path is `$TMPDIR/sh.xtool`. With this change it should be possible to `export XTL_TMPDIR=/var/tmp` if `/tmp` doesn't have enough space, which fixes #23.
26 lines
743 B
Swift
26 lines
743 B
Swift
import Foundation
|
|
|
|
extension Data {
|
|
// AsyncBytes is Darwin-only :/
|
|
|
|
package init(reading fileHandle: FileHandle) async throws {
|
|
#if canImport(Darwin)
|
|
self = try await fileHandle.bytes.reduce(into: Data()) { $0.append($1) }
|
|
#else
|
|
self = try fileHandle.readToEnd() ?? Data()
|
|
#endif
|
|
}
|
|
|
|
package init(reading file: URL) async throws {
|
|
#if canImport(Darwin)
|
|
self = try await file.resourceBytes.reduce(into: Data()) { $0.append($1) }
|
|
#else
|
|
try self.init(contentsOf: file)
|
|
#endif
|
|
}
|
|
}
|
|
|
|
package func stderrPrint(_ message: String, terminator: String = "\n") {
|
|
try? FileHandle.standardError.write(contentsOf: Data("\(message)\(terminator)".utf8))
|
|
}
|