wekan/packages/wekan-cfs-temp-store/internal.api.md
2021-04-29 13:26:49 +03:00

6.1 KiB

Public and Private API

API documentation automatically generated by docmeteor.


File: "tempStore.js" Where: {server}


##Temporary Storage

Temporary storage is used for chunked uploads until all chunks are received and all copies have been made or given up. In some cases, the original file is stored only in temporary storage (for example, if all copies do some manipulation in beforeSave). This is why we use the temporary file as the basis for each saved copy, and then remove it after all copies are saved.

Every chunk is saved as an individual temporary file. This is safer than attempting to write multiple incoming chunks to different positions in a single temporary file, which can lead to write conflicts.

Using temp files also allows us to easily resume uploads, even if the server restarts, and to keep the working memory clear. The FS.TempStore emits events that others are able to listen to

fs.TempStore {object}  Server

This property TempStore is defined in FS it's an event emitter*

FS.TempStore = new EventEmitter(); tempStore.js:28

fsTempstore.Storage {StorageAdapter}  Server

This property is private This property Storage is defined in FS.TempStore

This property is set to either FS.Store.FileSystem or FS.Store.GridFS

When and why: We normally default to cfs-filesystem unless its not installed. (we default to gridfs if installed) But if cfs-gridfs and cfs-worker is installed we default to cfs-gridfs

If cfs-gridfs and cfs-filesystem is not installed we log a warning. the user can set FS.TempStore.Storage them selfs eg.:

// Its important to set `internal: true` this lets the SA know that we
// are using this internally and it will give us direct SA api
FS.TempStore.Storage = new FS.Store.GridFS('_tempstore', { internal: true });

Note: This is considered as advanced use, its not a common pattern.

FS.TempStore.Storage = null; tempStore.js:54

We will not mount a storage adapter until needed. This allows us to check for the existance of FS.FileWorker, which is loaded after this package because it depends on this package.

XXX: TODO FS.TempStore.on('stored', function(fileObj, chunkCount, result) { This should work if we pass on result from the SA on stored event... fileObj.update({ $set: { chunkSum: 1, chunkCount: chunkCount, size: result.size } }); }); Stream implementation

_chunkPath([n])  Server

This method is private

Arguments

  • n {Number} (Optional)

Chunk number

Returns {String} Chunk naming convention

_chunkPath = function(n) { ... tempStore.js:104

_fileReference(fileObj, chunk)  Server

This method is private

Arguments

Returns {String} Generated SA specific fileKey for the chunk

Note: Calling function should call mountStorage() first, and make sure that fileObj is mounted.

_fileReference = function(fileObj, chunk, existing) { ... tempStore.js:118

fsTempstore.exists(File)  Server

This method exists is defined in FS.TempStore

Arguments

object

Returns {Boolean} Is this file, or parts of it, currently stored in the TempStore

FS.TempStore.exists = function(fileObj) { ... tempStore.js:145

fsTempstore.listParts(fileObj)  Server

This method listParts is defined in FS.TempStore

Arguments

Returns {Object} of parts already stored

TODO

* This is not yet implemented, milestone 1.1.0

FS.TempStore.listParts = function(fileObj) { ... tempStore.js:156

fsTempstore.removeFile(fileObj)  Server

This method removeFile is defined in FS.TempStore

Arguments

This function removes the file from tempstorage - it cares not if file is already removed or not found, goal is reached anyway.

FS.TempStore.removeFile = function(fileObj) { ... tempStore.js:169

fsTempstore.createWriteStream(fileObj, [options])  Server

This method createWriteStream is defined in FS.TempStore

Arguments

File to store in temporary storage

  • options {Number |[ String](# String)} (Optional)

Returns {Stream} Writeable stream

options of different types mean differnt things: undefined We store the file in one part (Normal server-side api usage)* Number the number is the part number total (multipart uploads will use this api)* String the string is the name of the store that wants to store file data (stores that want to sync their data to the rest of the files stores will use this)*

Note: fileObj must be mounted on a FS.Collection, it makes no sense to store otherwise

FS.TempStore.createWriteStream = function(fileObj, options) { ... tempStore.js:217

fsTempstore.createReadStream(fileObj)  Server

This method createReadStream is defined in FS.TempStore

Arguments

The file to read

Returns {Stream} Returns readable stream

FS.TempStore.createReadStream = function(fileObj) { ... tempStore.js:313