Skip to main content
reference

PrivMXStoreFileHandlerExtensions

A class providing a set of tools using SwiftNIO for uploading and downloading files with the use of PrivMXStore from PrivMX Endpoint.

Static Methods

getStoreFileUpdater(for:withReplacement:using:replacingPublicMeta:replacingPrivateMeta:replacingFileSize:chunkSize:)

Creates a handler for updating a file with a new data buffer.

public static func getStoreFileUpdater(
for fileId:String,
withReplacement sourceFile:FileHandle,
using storesApi:any PrivMXStore,
replacingPublicMeta publicMeta: Data,
replacingPrivateMeta privateMeta: Data,
replacingFileSize fileSize: Int64,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler

NameTypeDescription
fileIdStringThe ID of the file to be updated.
sourceFileFileHandleThe FileHandle (swift-nio) with new file content.
storesApiany PrivMXStoreThe API for interacting with the `PrivMXStore`.
publicMetaDataThe new public metadata for the file.
privateMetaDataThe new private metadata for the file.
fileSizeInt64The size of the file to be updated.
chunkSizeInt64The size of the chunks for the upload. Defaults to the recommended chunk size.

TypeDescription
PrivMXStoreFileHandler A new `PrivMXStoreFileHandler` instance configured for updating the file.

getStoreFileCreator(inStore:from:using:withPublicMeta:withPrivateMeta:fileSize:chunkSize:)

Creates a handler for creating a new file from a data buffer.

public static func getStoreFileCreator(
inStore storeId:String,
from sourceFile:FileHandle,
using storesApi:any PrivMXStore,
withPublicMeta publicMeta:Data,
withPrivateMeta privateMeta:Data,
fileSize: Int64,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler

NameTypeDescription
storeIdStringThe ID of the store where the file will be created.
sourceFileFileHandleThe FileHandle (swift-nio) with new file content.
storesApiany PrivMXStoreThe API for interacting with the `PrivMXStore`.
publicMetaDataThe public metadata for the new file.
privateMetaDataThe private metadata for the new file.
fileSizeInt64The size of the new file.
chunkSizeInt64The size of the chunks for the upload. Defaults to the recommended chunk size.

TypeDescription
PrivMXStoreFileHandler A new `PrivMXStoreFileHandler` instance configured for creating the file.

getStoreFileUpdater(for:withReplacementBuffer:using:replacingPublicMeta:replacingPrivateMeta:replacingFileSize:chunkSize:)

Creates a handler for updating a file with a new data buffer.

public static func getStoreFileUpdater(
for fileId:String,
withReplacementBuffer sourceBuffer:Data,
using storesApi:any PrivMXStore,
replacingPublicMeta publicMeta: Data,
replacingPrivateMeta privateMeta: Data,
replacingFileSize fileSize: Int64,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler

NameTypeDescription
fileIdStringThe ID of the file to be updated.
sourceBufferDataThe data buffer to replace the existing file content.
storesApiany PrivMXStoreThe API for interacting with the `PrivMXStore`.
publicMetaDataThe new public metadata for the file.
privateMetaDataThe new private metadata for the file.
fileSizeInt64The size of the file to be updated.
chunkSizeInt64The size of the chunks for the upload. Defaults to the recommended chunk size.

TypeDescription
PrivMXStoreFileHandler A new `PrivMXStoreFileHandler` instance configured for updating the file.

getStoreFileCreator(inStore:fromBuffer:using:withPublicMeta:withPrivateMeta:fileSize:chunkSize:)

Creates a handler for updating a file with a new data buffer.

public static func getStoreFileCreator(
inStore storeId:String,
fromBuffer sourceBuffer:Data,
using storesApi:any PrivMXStore,
withPublicMeta publicMeta:Data,
withPrivateMeta privateMeta:Data,
fileSize: Int64,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler

NameTypeDescription
storeIdString
sourceBufferDataThe data buffer to replace the existing file content.
storesApiany PrivMXStoreThe API for interacting with the `PrivMXStore`.
publicMetaDataThe new public metadata for the file.
privateMetaDataThe new private metadata for the file.
fileSizeInt64The size of the file to be updated.
chunkSizeInt64The size of the chunks for the upload. Defaults to the recommended chunk size.

TypeDescription
PrivMXStoreFileHandler A new `PrivMXStoreFileHandler` instance configured for updating the file.

getStoreFileReader(saveTo:readFrom:with:chunkSize:)

Creates a new handler for downloading a file and saving it to a local file.

public static func getStoreFileReader(
saveTo outputFile:FileHandle,
readFrom fileId:String,
with storesApi:any PrivMXStore,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler

NameTypeDescription
outputFileFileHandleThe local file handle (swift-nio) where the downloaded file content will be saved.
fileIdStringThe ID of the file to be downloaded from the `PrivMXStore`.
storesApiany PrivMXStoreThe API for interacting with the `PrivMXStore`.
chunkSizeInt64The size of the chunks for downloading. Defaults to the recommended chunk size.

TypeDescription
PrivMXStoreFileHandler A new `PrivMXStoreFileHandler` instance configured for downloading the file to the local file.

getStoreFileReader(readFrom:with:chunkSize:)

Creates a new handler for downloading a file to an internal buffer. This method allows downloading a file from the `PrivMXStore` directly into memory (a buffer). To retrieve the buffer after the download, call `getBuffer()`.

public static func getStoreFileReader(
readFrom fileId:String,
with storesApi:any PrivMXStore,
chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize
) throws -> PrivMXStoreFileHandler

NameTypeDescription
fileIdStringThe ID of the file to be downloaded from the `PrivMXStore`.
storesApiany PrivMXStoreThe API for interacting with the `PrivMXStore`.
chunkSizeInt64The size of the chunks for downloading. Defaults to the recommended chunk size.

TypeDescription
PrivMXStoreFileHandler A new `PrivMXStoreFileHandler` instance configured for downloading the file into the buffer.