CollectionFS, temporary storage
API documentation automatically generated by docmeteor.
##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.
This property TempStore is defined in FS
it's an event emitter*
FS.TempStore = new EventEmitter();
tempStore.js:28
- 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 } }); });
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
-
This method createWriteStream is defined in FS.TempStore
Arguments
File to store in temporary storage
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
-
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