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
urlpass 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.directoryURLwill 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.invalidPathDeclaration
Swift
func createFile(from data: Data, toDirectory directoryURL: URL? = nil, filename: String, fileExtension: String? = nil) -> BoolParameters
dataRaw object to save.
directoryURLdirectoryURL to save file.
filenameFilename.
fileExtensionFile extension.
Return Value
Boolean of success.
-
createFilespec(_:toDirectory:)Extension method -
rename(original:to:)Extension methodRename or move file.
Throws
FileStorageError.invalidPathDeclaration
Swift
func rename(original: URL, to toURL: URL) throwsParameters
originaloriginal file location in storage.
toURLFile new location
URL. -
moveFile(at:to:)Extension methodRename or move file.
Throws
FileStorageError.invalidPathDeclaration
Swift
func moveFile(at atURL: URL, to toURL: URL) throwsParameters
originaloriginal file location in storage.
toURLFile 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 -> URLParameters
atURLFile location in storage.
toURLTo directory.
fileNameFilename.
fileExtensionFile extension.
-
removeFile(fileName:fileExtension:at:)Extension methodRemoves file by filename.
Declaration
Swift
func removeFile(fileName: String, fileExtension: String? = nil, at directoryURL: URL? = nil) throwsParameters
fileNameFilename.
fileExtensionFile extension.
directoryURLdirectory.
-
removeFile(_:at:)Extension methodRemoves a file.
Throws
FileStorageError.invalidPath,FileStorageError.invalidFileNameOrExtentision,FileStorageError.fileNotFoundDeclaration
Swift
func removeFile(_ url: URL, at directoryURL: URL? = nil) throwsParameters
urlFile remote location.
-
removeFilespec(_:at:)Extension methodRemoves Filespec.
Declaration
Swift
func removeFilespec(_ url: URL?, at directoryURL: URL? = nil) throwsParameters
urlFile remote location.
directoryURLdirectory.
-
removeFile(at:)Extension methodRemoves a file by file local location.
Declaration
Swift
func removeFile(at fileURL: URL) throwsParameters
fileURLFile local location.
-
removeDirectory(_:)Extension methodRemove
FileStorageManageable.directoryURL.Throws
FileStorageError.invalidPathDeclaration
Swift
func removeDirectory(_ directory: URL? = nil) throwsParameters
directorydirectory.
-
removeFilesFromDirectory()Extension methodRemove all files from
FileStorageManageable.directoryURL.Directory self won’t be removed.
Throws
FileStorageError.invalidPathDeclaration
Swift
func removeFilesFromDirectory() throws
FileWriting Protocol Reference