Skip to content

Commit 88c9aa7

Browse files
committed
Update Readme in relation to initFileFn and readFileFn hooks
1 parent f7a4ce9 commit 88c9aa7

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ function, it will be passed a FlowFile, a FlowChunk and isTest boolean (Default:
119119
* `allowDuplicateUploads ` Once a file is uploaded, allow reupload of the same file. By default, if a file is already uploaded, it will be skipped unless the file is removed from the existing Flow object. (Default: `false`)
120120
* `prioritizeFirstAndLastChunk` Prioritize first and last chunks of all files. This can be handy if you can determine if a file is valid for your service from only the first or last chunk. For example, photo or video meta data is usually located in the first part of a file, making it easy to test support from only the first chunk. (Default: `false`)
121121
* `testChunks` Make a GET request to the server for each chunks to see if it already exists. If implemented on the server-side, this will allow for upload resumes even after a browser crash or even a computer restart. (Default: `true`)
122-
* `preprocess` Optional function to process each chunk before testing & sending. Function is passed the chunk as parameter, and should call the `preprocessFinished` method on the chunk when finished. (Default: `null`)
123-
* `generateUniqueIdentifier` Override the function that generates unique identifiers for each file. (Default: `null`)
122+
* `preprocess` Optional function to process each chunk before testing & sending. To the function it will be passed the chunk as parameter, and should call the `preprocessFinished` method on the chunk when finished. (Default: `null`)
123+
* `initFileFn` Optional function to initialize the fileObject. To the function it will be passed a FlowFile and a FlowChunk arguments.
124+
* `readFileFn` Optional function wrapping reading operation from the original file. To the function it will be passed the FlowFile, the startByte and endByte, the fileType and the FlowChunk.
125+
* `generateUniqueIdentifier` Override the function that generates unique identifiers for each file. (Default: `null`)
124126
* `maxChunkRetries` The maximum number of retries for a chunk before the upload is failed. Valid values are any positive integer and `undefined` for no limit. (Default: `0`)
125127
* `chunkRetryInterval` The number of milliseconds to wait before retrying a chunk on a non-permanent error. Valid values are any positive integer and `undefined` for immediate retry. (Default: `undefined`)
126128
* `progressCallbacksInterval` The time interval in milliseconds between progress reports. Set it

src/flow.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,9 @@
917917
* @function
918918
*/
919919
bootstrap: function () {
920-
evalOpts(this.flowObj.opts.initFileFn, this.fileObj, this);
920+
if (typeof this.flowObj.opts.initFileFn === "function") {
921+
this.flowObj.opts.initFileFn(this);
922+
}
921923

922924
this.abort(true);
923925
this.error = false;
@@ -1047,15 +1049,20 @@
10471049
/**
10481050
* Default read function using the webAPI
10491051
*
1050-
* @function webAPIFileRead(chunk, startByte, endByte, fileType)
1052+
* @function webAPIFileRead(fileObj, fileType, startByte, endByte, chunk)
10511053
*
10521054
*/
1053-
function webAPIFileRead(chunk, startByte, endByte, fileType) {
1054-
var function_name = (chunk.fileObj.file.slice ? 'slice' :
1055-
(chunk.fileObj.file.mozSlice ? 'mozSlice' :
1056-
(chunk.fileObj.file.webkitSlice ? 'webkitSlice' :
1057-
'slice')));
1058-
chunk.readFinished(chunk.fileObj.file[function_name](startByte, endByte, fileType));
1055+
function webAPIFileRead(fileObj, fileType, startByte, endByte, chunk) {
1056+
var function_name = 'slice';
1057+
1058+
if (fileObj.file.slice)
1059+
function_name = 'slice';
1060+
else if (fileObj.file.mozSlice)
1061+
function_name = 'mozSlice';
1062+
else if (fileObj.file.webkitSlice)
1063+
function_name = 'webkitSlice';
1064+
1065+
chunk.readFinished(fileObj.file[function_name](startByte, endByte, fileType));
10591066
}
10601067

10611068

@@ -1324,7 +1331,7 @@
13241331
switch (this.readState) {
13251332
case 0:
13261333
this.readState = 1;
1327-
read(this, this.startByte, this.endByte, this.fileType);
1334+
read(this.fileObj, this.startByte, this.endByte, this.fileType, this);
13281335
return;
13291336
case 1:
13301337
return;

0 commit comments

Comments
 (0)