Skip to content

Commit 517c95a

Browse files
v1.0.414
[Bot] push changes from Files.com
1 parent adcfd74 commit 517c95a

File tree

7 files changed

+242
-126
lines changed

7 files changed

+242
-126
lines changed

_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.413
1+
1.0.414

lib/Files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var endpointPrefix = '/api/rest/v1';
1111
var apiKey;
1212
var baseUrl = 'https://app.files.com';
1313
var sessionId = null;
14-
var version = "1.0.413";
14+
var version = "1.0.414";
1515
var userAgent = "Files.com JavaScript SDK v".concat(version);
1616
var logLevel = _Logger.LogLevel.INFO;
1717
var debugRequest = false;

lib/models/File.js

+122-75
Original file line numberDiff line numberDiff line change
@@ -936,118 +936,165 @@ _class = File;
936936
var chunks = [];
937937
var length = 0;
938938
var concurrentUploads = [];
939+
var chunkBuffer = null;
940+
var streamEnded = false;
941+
var handleStreamEnd = /*#__PURE__*/function () {
942+
var _ref19 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15() {
943+
var _options$getAgentForU, buffer, nextFileUploadPart, upload_uri, agent, response, createdFile;
944+
return _regenerator.default.wrap(function _callee15$(_context15) {
945+
while (1) switch (_context15.prev = _context15.next) {
946+
case 0:
947+
if (!(chunkBuffer !== null || !streamEnded)) {
948+
_context15.next = 2;
949+
break;
950+
}
951+
return _context15.abrupt("return");
952+
case 2:
953+
_context15.prev = 2;
954+
if (!(chunks.length > 0)) {
955+
_context15.next = 11;
956+
break;
957+
}
958+
buffer = _safeBuffer.Buffer.concat(chunks);
959+
_context15.next = 7;
960+
return _class._continueUpload(destinationPath, ++part, firstFileUploadPart, options);
961+
case 7:
962+
nextFileUploadPart = _context15.sent;
963+
upload_uri = determinePartUploadUri(nextFileUploadPart); // instantiate an httpsAgent dynamically if needed
964+
agent = ((_options$getAgentForU = options.getAgentForUrl) === null || _options$getAgentForU === void 0 ? void 0 : _options$getAgentForU.call(options, upload_uri)) || (options === null || options === void 0 ? void 0 : options.agent);
965+
concurrentUploads.push(_Api.default.sendFilePart(upload_uri, 'PUT', buffer, {
966+
agent: agent
967+
}));
968+
case 11:
969+
_context15.next = 13;
970+
return Promise.all(concurrentUploads);
971+
case 13:
972+
_context15.next = 15;
973+
return _class._completeUpload(firstFileUploadPart, options);
974+
case 15:
975+
response = _context15.sent;
976+
createdFile = new _class(response.data, options);
977+
resolve(createdFile);
978+
_context15.next = 23;
979+
break;
980+
case 20:
981+
_context15.prev = 20;
982+
_context15.t0 = _context15["catch"](2);
983+
reject(_context15.t0);
984+
case 23:
985+
case "end":
986+
return _context15.stop();
987+
}
988+
}, _callee15, null, [[2, 20]]);
989+
}));
990+
return function handleStreamEnd() {
991+
return _ref19.apply(this, arguments);
992+
};
993+
}();
939994
readableStream.on('error', function (error) {
940995
reject(error);
941996
});
997+
998+
// note that for a network stream, each chunk is typically less than partsize * 2, but
999+
// if a stream has been created based on very large data, it's possible for a chunk to
1000+
// contain the entire file and we could get a single chunk with length >= partsize * 3
9421001
readableStream.on('data', /*#__PURE__*/function () {
943-
var _ref19 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(chunk) {
944-
var nextLength, excessLength, chunkBuffer, _options$getAgentForU, tailLength, lastChunkForPart, firstChunkForNextPart, buffer, nextFileUploadPart, upload_uri, agent, uploadPromise;
945-
return _regenerator.default.wrap(function _callee15$(_context15) {
946-
while (1) switch (_context15.prev = _context15.next) {
1002+
var _ref20 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(chunk) {
1003+
var excessLength, _options$getAgentForU2, lengthForEndOfCurrentPart, lastChunkForCurrentPart, chunkBufferAfterCurrentPart, buffer, nextFileUploadPart, upload_uri, agent, uploadPromise, isNextChunkAtLeastOnePart;
1004+
return _regenerator.default.wrap(function _callee16$(_context16) {
1005+
while (1) switch (_context16.prev = _context16.next) {
9471006
case 0:
948-
_context15.prev = 0;
949-
nextLength = length + chunk.length;
950-
excessLength = nextLength - firstFileUploadPart.partsize;
1007+
_context16.prev = 0;
1008+
excessLength = length + chunk.length - firstFileUploadPart.partsize;
9511009
chunkBuffer = _safeBuffer.Buffer.from(chunk);
9521010
if (!(excessLength > 0)) {
953-
_context15.next = 28;
1011+
_context16.next = 30;
9541012
break;
9551013
}
9561014
readableStream.pause();
957-
1015+
case 5:
1016+
if (!chunkBuffer) {
1017+
_context16.next = 27;
1018+
break;
1019+
}
9581020
// the amount to append this last part with to make it exactly the full partsize
959-
tailLength = chunkBuffer.length - excessLength;
960-
lastChunkForPart = chunkBuffer.subarray(0, tailLength);
961-
firstChunkForNextPart = chunkBuffer.subarray(tailLength);
962-
chunks.push(lastChunkForPart);
1021+
lengthForEndOfCurrentPart = chunkBuffer.length - excessLength;
1022+
lastChunkForCurrentPart = chunkBuffer.subarray(0, lengthForEndOfCurrentPart);
1023+
chunkBufferAfterCurrentPart = chunkBuffer.subarray(lengthForEndOfCurrentPart);
1024+
chunks.push(lastChunkForCurrentPart);
9631025
buffer = _safeBuffer.Buffer.concat(chunks);
964-
_context15.next = 13;
1026+
_context16.next = 13;
9651027
return _class._continueUpload(destinationPath, ++part, firstFileUploadPart, options);
9661028
case 13:
967-
nextFileUploadPart = _context15.sent;
1029+
nextFileUploadPart = _context16.sent;
9681030
upload_uri = determinePartUploadUri(nextFileUploadPart); // instantiate an httpsAgent dynamically if needed
969-
agent = ((_options$getAgentForU = options.getAgentForUrl) === null || _options$getAgentForU === void 0 ? void 0 : _options$getAgentForU.call(options, upload_uri)) || (options === null || options === void 0 ? void 0 : options.agent);
1031+
agent = ((_options$getAgentForU2 = options.getAgentForUrl) === null || _options$getAgentForU2 === void 0 ? void 0 : _options$getAgentForU2.call(options, upload_uri)) || (options === null || options === void 0 ? void 0 : options.agent);
9701032
uploadPromise = _Api.default.sendFilePart(upload_uri, 'PUT', buffer, {
9711033
agent: agent
9721034
});
9731035
if (!firstFileUploadPart.parallel_parts) {
974-
_context15.next = 21;
1036+
_context16.next = 21;
9751037
break;
9761038
}
9771039
concurrentUploads.push(uploadPromise);
978-
_context15.next = 23;
1040+
_context16.next = 23;
9791041
break;
9801042
case 21:
981-
_context15.next = 23;
1043+
_context16.next = 23;
9821044
return uploadPromise;
9831045
case 23:
984-
chunks = [firstChunkForNextPart];
985-
length = firstChunkForNextPart.length;
1046+
// determine if the remainder of the excess chunk data is too large to be a single part
1047+
isNextChunkAtLeastOnePart = chunkBufferAfterCurrentPart.length >= firstFileUploadPart.partsize; // the excess data contains >= 1 full part, so we'll loop again to enqueue
1048+
// the next part for upload and continue processing any excess beyond that
1049+
if (isNextChunkAtLeastOnePart) {
1050+
chunks = [];
1051+
length = 0;
1052+
chunkBuffer = chunkBufferAfterCurrentPart;
1053+
excessLength = chunkBuffer.length - firstFileUploadPart.partsize;
1054+
// the excess data is less than a full part, so we'll enqueue it
1055+
} else if (chunkBufferAfterCurrentPart.length > 0) {
1056+
chunks = [chunkBufferAfterCurrentPart];
1057+
length = chunkBufferAfterCurrentPart.length;
1058+
chunkBuffer = null;
1059+
} else {
1060+
chunkBuffer = null;
1061+
}
1062+
_context16.next = 5;
1063+
break;
1064+
case 27:
9861065
readableStream.resume();
987-
_context15.next = 30;
1066+
_context16.next = 33;
9881067
break;
989-
case 28:
1068+
case 30:
9901069
chunks.push(chunkBuffer);
9911070
length += chunk.length;
992-
case 30:
993-
_context15.next = 35;
1071+
chunkBuffer = null;
1072+
case 33:
1073+
if (streamEnded) {
1074+
handleStreamEnd();
1075+
}
1076+
_context16.next = 39;
9941077
break;
995-
case 32:
996-
_context15.prev = 32;
997-
_context15.t0 = _context15["catch"](0);
998-
reject(_context15.t0);
999-
case 35:
1078+
case 36:
1079+
_context16.prev = 36;
1080+
_context16.t0 = _context16["catch"](0);
1081+
reject(_context16.t0);
1082+
case 39:
10001083
case "end":
1001-
return _context15.stop();
1084+
return _context16.stop();
10021085
}
1003-
}, _callee15, null, [[0, 32]]);
1086+
}, _callee16, null, [[0, 36]]);
10041087
}));
10051088
return function (_x20) {
1006-
return _ref19.apply(this, arguments);
1089+
return _ref20.apply(this, arguments);
10071090
};
10081091
}());
1009-
readableStream.on('end', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16() {
1010-
var _options$getAgentForU2, buffer, nextFileUploadPart, upload_uri, agent, response, createdFile;
1011-
return _regenerator.default.wrap(function _callee16$(_context16) {
1012-
while (1) switch (_context16.prev = _context16.next) {
1013-
case 0:
1014-
_context16.prev = 0;
1015-
if (!(chunks.length > 0)) {
1016-
_context16.next = 9;
1017-
break;
1018-
}
1019-
buffer = _safeBuffer.Buffer.concat(chunks);
1020-
_context16.next = 5;
1021-
return _class._continueUpload(destinationPath, ++part, firstFileUploadPart, options);
1022-
case 5:
1023-
nextFileUploadPart = _context16.sent;
1024-
upload_uri = determinePartUploadUri(nextFileUploadPart); // instantiate an httpsAgent dynamically if needed
1025-
agent = ((_options$getAgentForU2 = options.getAgentForUrl) === null || _options$getAgentForU2 === void 0 ? void 0 : _options$getAgentForU2.call(options, upload_uri)) || (options === null || options === void 0 ? void 0 : options.agent);
1026-
concurrentUploads.push(_Api.default.sendFilePart(upload_uri, 'PUT', buffer, {
1027-
agent: agent
1028-
}));
1029-
case 9:
1030-
_context16.next = 11;
1031-
return Promise.all(concurrentUploads);
1032-
case 11:
1033-
_context16.next = 13;
1034-
return _class._completeUpload(firstFileUploadPart, options);
1035-
case 13:
1036-
response = _context16.sent;
1037-
createdFile = new _class(response.data, options);
1038-
resolve(createdFile);
1039-
_context16.next = 21;
1040-
break;
1041-
case 18:
1042-
_context16.prev = 18;
1043-
_context16.t0 = _context16["catch"](0);
1044-
reject(_context16.t0);
1045-
case 21:
1046-
case "end":
1047-
return _context16.stop();
1048-
}
1049-
}, _callee16, null, [[0, 18]]);
1050-
})));
1092+
1093+
// note that this event may occur while there is still data being processed above
1094+
readableStream.on('end', function () {
1095+
streamEnded = true;
1096+
handleStreamEnd();
1097+
});
10511098
});
10521099
case 10:
10531100
file = _context17.sent;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "files.com",
3-
"version": "1.0.413",
3+
"version": "1.0.414",
44
"description": "Files.com SDK for JavaScript",
55
"keywords": [
66
"files.com",

src/Files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const endpointPrefix = '/api/rest/v1'
55
let apiKey
66
let baseUrl = 'https://app.files.com'
77
let sessionId = null
8-
let version = "1.0.413"
8+
let version = "1.0.414"
99
let userAgent = `Files.com JavaScript SDK v${version}`
1010

1111
let logLevel = LogLevel.INFO

0 commit comments

Comments
 (0)