Skip to content

Commit

Permalink
Remove string functions add FileManager as default
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif committed Jan 31, 2024
1 parent dd9fa55 commit 538e54e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
1 change: 1 addition & 0 deletions Sources/AppState/Application/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ open class Application: NSObject {
/// Loads the default dependencies for use in Application.
private func loadDefaultDependencies() {
load(dependency: \.userDefaults)
load(dependency: \.fileManager)
}

#if !os(Linux) && !os(Windows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,6 @@ extension FileManager {
return try JSONDecoder().decode(Value.self, from: data)
}

/// Read a file's data as the type `String`
///
/// - Parameters:
/// - path: The path to the directory containing the file. The default is `.`, which means the current working directory.
/// - filename: The name of the file to read.
/// - encoding: The String.Encoding to use to get the string.
/// - Returns: The file's data decoded as an instance of `String`.
/// - Throws: If there's an error reading the file or decoding its data.
func string(
path: String = ".",
filename: String,
encoding: String.Encoding = .utf8
) throws -> String {
let data = try data(
path: path,
filename: filename
)

guard let string = String(data: data, encoding: encoding) else {
throw FileError.invalidStringFromData
}

return string
}

/// Read a file's data
///
/// - Parameters:
Expand Down Expand Up @@ -124,34 +99,6 @@ extension FileManager {
)
}

/// Write a string to a file
///
/// - Parameters:
/// - string: The string to write to the file.
/// - path: The path to the directory where the file should be written. The default is `.`, which means the current working directory.
/// - filename: The name of the file to write.
/// - using: The String.Encoding to encode the string with. The default is `.utf8`.
/// - base64Encoded: A Boolean value indicating whether the data should be Base64-encoded before writing to the file. The default is `true`.
/// - Throws: If there's an error writing the data to the file.
func out(
string: String,
path: String = ".",
filename: String,
using stringEncoding: String.Encoding = .utf8,
base64Encoded: Bool = true
) throws {
guard let data = string.data(using: stringEncoding) else {
throw FileError.invalidStringFromData
}

try out(
data: data,
path: path,
filename: filename,
base64Encoded: base64Encoded
)
}

/// Write data to a file
///
/// - Parameters:
Expand Down

0 comments on commit 538e54e

Please sign in to comment.