FileWriting
public protocol FileWriting : FileStorageManageable
Represent file writing functionality that could be used within FileStorageManageable
-
createDirectoryIfNeeded(_:)
Extension methodCreate 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. -
createFile(from:toDirectory:filename:fileExtension:)
Extension methodSave 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.
-
createFilespec(_:toDirectory:)
Extension method -
rename(original:to:)
Extension methodRename 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 methodRename 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
. -
moveFile(at:to:withFileName:fileExtension:)
Extension methodRename 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.
-
removeFile(fileName:fileExtension:at:)
Extension methodRemoves 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 methodRemoves 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 methodRemoves Filespec.
Declaration
Swift
func removeFilespec(_ url: URL?, at directoryURL: URL? = nil) throws
Parameters
url
File remote location.
directoryURL
directory.
-
removeFile(at:)
Extension methodRemoves a file by file local location.
Declaration
Swift
func removeFile(at fileURL: URL) throws
Parameters
fileURL
File local location.
-
removeDirectory(_:)
Extension methodRemove
FileStorageManageable.directoryURL
.Throws
FileStorageError.invalidPath
Declaration
Swift
func removeDirectory(_ directory: URL? = nil) throws
Parameters
directory
directory.
-
removeFilesFromDirectory()
Extension methodRemove all files from
FileStorageManageable.directoryURL
.Directory self won’t be removed.
Throws
FileStorageError.invalidPath
Declaration
Swift
func removeFilesFromDirectory() throws