FileWriting

public protocol FileWriting : FileStorageManageable

Represent file writing functionality that could be used within FileStorageManageable

  • createDirectoryIfNeeded(_:) Extension method

    Create a directory if does not exist.

    Declaration

    Swift

    func createDirectoryIfNeeded(_ url: URL? = nil)

    Parameters

    url

    pass directory url to create, in case if needed. Use FileStorageManageable.urlFor(directory: String) to create an url from relative directory path.

  • Save the file from data object to directoryURL, with given filename and fileExtension.

    If directoryURL is nil, FileStorageManageable.directoryURL will be used. The directory will be created in case if needed. The file will be overridden if it already exists in the path.

    Throws

    FileStorageError.invalidPath

    Declaration

    Swift

    func createFile(from data: Data, toDirectory directoryURL: URL? = nil, filename: String, fileExtension: String? = nil) -> Bool

    Parameters

    data

    Raw object to save.

    directoryURL

    directoryURL to save file.

    filename

    Filename.

    fileExtension

    File extension.

    Return Value

    Boolean of success.

  • Save a JSON file from Filespec object.

    Declaration

    Swift

    func createFilespec(_ filespec: Filespec, toDirectory directoryURL: URL? = nil) -> Bool

    Parameters

    filespec

    filespec object that will be saved.

    directoryURL

    directoryURL to save file.

    Return Value

    Boolean of success.

  • rename(original:to:) Extension method

    Rename or move file.

    Throws

    FileStorageError.invalidPath

    Declaration

    Swift

    func rename(original: URL, to toURL: URL) throws

    Parameters

    original

    original file location in storage.

    toURL

    File new location URL.

  • moveFile(at:to:) Extension method

    Rename or move file.

    Throws

    FileStorageError.invalidPath

    Declaration

    Swift

    func moveFile(at atURL: URL, to toURL: URL) throws

    Parameters

    original

    original file location in storage.

    toURL

    File new location URL.

  • Rename or move file.

    File will be saved to FileStorageManageable.directoryURL.

    Declaration

    Swift

    func moveFile(at atURL: URL, to toDirectory: URL? = nil, withFileName fileName: String, fileExtension: String? = nil) throws -> URL

    Parameters

    atURL

    File location in storage.

    toURL

    To directory.

    fileName

    Filename.

    fileExtension

    File extension.

  • Removes file by filename.

    Declaration

    Swift

    func removeFile(fileName: String, fileExtension: String? = nil, at directoryURL: URL? = nil) throws

    Parameters

    fileName

    Filename.

    fileExtension

    File extension.

    directoryURL

    directory.

  • removeFile(_:at:) Extension method

    Removes a file.

    Throws

    FileStorageError.invalidPath, FileStorageError.invalidFileNameOrExtentision, FileStorageError.fileNotFound

    Declaration

    Swift

    func removeFile(_ url: URL, at directoryURL: URL? = nil) throws

    Parameters

    url

    File remote location.

  • removeFilespec(_:at:) Extension method

    Removes Filespec.

    Declaration

    Swift

    func removeFilespec(_ url: URL?, at directoryURL: URL? = nil) throws

    Parameters

    url

    File remote location.

    directoryURL

    directory.

  • removeFile(at:) Extension method

    Removes a file by file local location.

    Declaration

    Swift

    func removeFile(at fileURL: URL) throws

    Parameters

    fileURL

    File local location.

  • removeDirectory(_:) Extension method

    Remove FileStorageManageable.directoryURL.

    Throws

    FileStorageError.invalidPath

    Declaration

    Swift

    func removeDirectory(_ directory: URL? = nil) throws

    Parameters

    directory

    directory.

  • removeFilesFromDirectory() Extension method

    Remove all files from FileStorageManageable.directoryURL.

    Directory self won’t be removed.

    Throws

    FileStorageError.invalidPath

    Declaration

    Swift

    func removeFilesFromDirectory() throws