files.com 1.0.207 → 1.0.210

Sign up to get free protection for your applications and to get access to all the features.
@@ -986,7 +986,7 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
986
986
  };
987
987
  }());
988
988
  (0, _defineProperty2.default)(File, "_completeUpload", /*#__PURE__*/function () {
989
- var _ref15 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(fileUploadPart) {
989
+ var _ref15 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(firstFileUploadPart) {
990
990
  var params;
991
991
  return _regenerator.default.wrap(function _callee13$(_context13) {
992
992
  while (1) {
@@ -994,9 +994,9 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
994
994
  case 0:
995
995
  params = {
996
996
  action: 'end',
997
- ref: fileUploadPart.ref
997
+ ref: firstFileUploadPart.ref
998
998
  };
999
- return _context13.abrupt("return", _Api.default.sendRequest("/files/".concat(encodeURIComponent(fileUploadPart.path)), 'POST', params));
999
+ return _context13.abrupt("return", _Api.default.sendRequest("/files/".concat(encodeURIComponent(firstFileUploadPart.path)), 'POST', params));
1000
1000
 
1001
1001
  case 2:
1002
1002
  case "end":
@@ -1012,7 +1012,7 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
1012
1012
  }());
1013
1013
  (0, _defineProperty2.default)(File, "uploadStream", /*#__PURE__*/function () {
1014
1014
  var _ref16 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(destinationPath, readableStream, params) {
1015
- var fileUploadPart, file;
1015
+ var firstFileUploadPart, file;
1016
1016
  return _regenerator.default.wrap(function _callee16$(_context16) {
1017
1017
  while (1) {
1018
1018
  switch (_context16.prev = _context16.next) {
@@ -1021,9 +1021,9 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
1021
1021
  return File._openUpload(destinationPath, params);
1022
1022
 
1023
1023
  case 2:
1024
- fileUploadPart = _context16.sent;
1024
+ firstFileUploadPart = _context16.sent;
1025
1025
 
1026
- if (fileUploadPart) {
1026
+ if (firstFileUploadPart) {
1027
1027
  _context16.next = 5;
1028
1028
  break;
1029
1029
  }
@@ -1037,55 +1037,63 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
1037
1037
  var part = 0;
1038
1038
  var chunks = [];
1039
1039
  var length = 0;
1040
+ var concurrentUploads = [];
1040
1041
  readableStream.on('error', function (error) {
1041
1042
  reject(error);
1042
1043
  });
1043
1044
  readableStream.on('data', /*#__PURE__*/function () {
1044
1045
  var _ref17 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(chunk) {
1045
- var buffer, nextFileUploadPart;
1046
+ var nextLength, excessLength, chunkBuffer, lastChunkForPart, firstChunkForNextPart, buffer, nextFileUploadPart;
1046
1047
  return _regenerator.default.wrap(function _callee14$(_context14) {
1047
1048
  while (1) {
1048
1049
  switch (_context14.prev = _context14.next) {
1049
1050
  case 0:
1050
1051
  _context14.prev = 0;
1051
- length += chunk.length;
1052
+ nextLength = length + chunk.length;
1053
+ excessLength = nextLength - firstFileUploadPart.partsize;
1054
+ chunkBuffer = _safeBuffer.Buffer.from(chunk);
1052
1055
 
1053
- if (!(length > fileUploadPart.partsize)) {
1054
- _context14.next = 13;
1056
+ if (!(excessLength > 0)) {
1057
+ _context14.next = 19;
1055
1058
  break;
1056
1059
  }
1057
1060
 
1058
1061
  readableStream.pause();
1062
+ lastChunkForPart = chunkBuffer.subarray(0, excessLength);
1063
+ firstChunkForNextPart = chunkBuffer.subarray(excessLength);
1064
+ chunks.push(lastChunkForPart);
1059
1065
  buffer = _safeBuffer.Buffer.concat(chunks);
1060
- _context14.next = 7;
1061
- return File._continueUpload(destinationPath, ++part, fileUploadPart);
1066
+ _context14.next = 12;
1067
+ return File._continueUpload(destinationPath, ++part, firstFileUploadPart);
1062
1068
 
1063
- case 7:
1069
+ case 12:
1064
1070
  nextFileUploadPart = _context14.sent;
1065
- _context14.next = 10;
1066
- return _Api.default.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer);
1067
-
1068
- case 10:
1069
- chunks = [];
1070
- length = 0;
1071
+ concurrentUploads.push(_Api.default.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer));
1072
+ chunks = [firstChunkForNextPart];
1073
+ length = 1;
1071
1074
  readableStream.resume();
1075
+ _context14.next = 21;
1076
+ break;
1072
1077
 
1073
- case 13:
1074
- chunks.push(_safeBuffer.Buffer.from(chunk));
1075
- _context14.next = 19;
1078
+ case 19:
1079
+ chunks.push(chunkBuffer);
1080
+ length += chunk.length;
1081
+
1082
+ case 21:
1083
+ _context14.next = 26;
1076
1084
  break;
1077
1085
 
1078
- case 16:
1079
- _context14.prev = 16;
1086
+ case 23:
1087
+ _context14.prev = 23;
1080
1088
  _context14.t0 = _context14["catch"](0);
1081
1089
  reject(_context14.t0);
1082
1090
 
1083
- case 19:
1091
+ case 26:
1084
1092
  case "end":
1085
1093
  return _context14.stop();
1086
1094
  }
1087
1095
  }
1088
- }, _callee14, null, [[0, 16]]);
1096
+ }, _callee14, null, [[0, 23]]);
1089
1097
  }));
1090
1098
 
1091
1099
  return function (_x14) {
@@ -1101,41 +1109,44 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
1101
1109
  _context15.prev = 0;
1102
1110
 
1103
1111
  if (!(chunks.length > 0)) {
1104
- _context15.next = 8;
1112
+ _context15.next = 7;
1105
1113
  break;
1106
1114
  }
1107
1115
 
1108
1116
  buffer = _safeBuffer.Buffer.concat(chunks);
1109
1117
  _context15.next = 5;
1110
- return File._continueUpload(destinationPath, ++part, fileUploadPart);
1118
+ return File._continueUpload(destinationPath, ++part, firstFileUploadPart);
1111
1119
 
1112
1120
  case 5:
1113
1121
  nextFileUploadPart = _context15.sent;
1114
- _context15.next = 8;
1115
- return _Api.default.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer);
1122
+ concurrentUploads.push(_Api.default.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer));
1123
+
1124
+ case 7:
1125
+ _context15.next = 9;
1126
+ return Promise.all(concurrentUploads);
1116
1127
 
1117
- case 8:
1118
- _context15.next = 10;
1119
- return File._completeUpload(fileUploadPart);
1128
+ case 9:
1129
+ _context15.next = 11;
1130
+ return File._completeUpload(firstFileUploadPart);
1120
1131
 
1121
- case 10:
1132
+ case 11:
1122
1133
  response = _context15.sent;
1123
1134
  createdFile = new File(response.data);
1124
1135
  resolve(createdFile);
1125
- _context15.next = 18;
1136
+ _context15.next = 19;
1126
1137
  break;
1127
1138
 
1128
- case 15:
1129
- _context15.prev = 15;
1139
+ case 16:
1140
+ _context15.prev = 16;
1130
1141
  _context15.t0 = _context15["catch"](0);
1131
1142
  reject(_context15.t0);
1132
1143
 
1133
- case 18:
1144
+ case 19:
1134
1145
  case "end":
1135
1146
  return _context15.stop();
1136
1147
  }
1137
1148
  }
1138
- }, _callee15, null, [[0, 15]]);
1149
+ }, _callee15, null, [[0, 16]]);
1139
1150
  })));
1140
1151
  });
1141
1152
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "files.com",
3
- "version": "1.0.207",
3
+ "version": "1.0.210",
4
4
  "description": "Files.com SDK for JavaScript",
5
5
  "keywords": [
6
6
  "files.com",
@@ -20,8 +20,8 @@
20
20
  "main": "lib/files.js",
21
21
  "dependencies": {
22
22
  "@babel/runtime": "^7.10.3",
23
- "axios": "^0.19.2",
24
- "axios-retry": "^3.1.8",
23
+ "axios": "0.27.2",
24
+ "axios-retry": "3.3.1",
25
25
  "readable-stream": "^3.6.0",
26
26
  "safe-buffer": "^5.1.1",
27
27
  "uuid": "^3.3.2"
package/src/Errors.js CHANGED
@@ -167,6 +167,7 @@ export class NotAuthorized_WritePermissionRequiredError extends NotAuthorizedErr
167
167
  export class NotAuthorized_ZipDownloadIpMismatchError extends NotAuthorizedError { constructor(message, code) { super(message, code); this.name = 'NotAuthorized_ZipDownloadIpMismatchError' } } errorClasses.NotAuthorized_ZipDownloadIpMismatchError = NotAuthorized_ZipDownloadIpMismatchError
168
168
  export class NotFound_ApiKeyNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_ApiKeyNotFoundError' } } errorClasses.NotFound_ApiKeyNotFoundError = NotFound_ApiKeyNotFoundError
169
169
  export class NotFound_BundlePathNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_BundlePathNotFoundError' } } errorClasses.NotFound_BundlePathNotFoundError = NotFound_BundlePathNotFoundError
170
+ export class NotFound_BundleRegistrationNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_BundleRegistrationNotFoundError' } } errorClasses.NotFound_BundleRegistrationNotFoundError = NotFound_BundleRegistrationNotFoundError
170
171
  export class NotFound_CodeNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_CodeNotFoundError' } } errorClasses.NotFound_CodeNotFoundError = NotFound_CodeNotFoundError
171
172
  export class NotFound_FileNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_FileNotFoundError' } } errorClasses.NotFound_FileNotFoundError = NotFound_FileNotFoundError
172
173
  export class NotFound_FileUploadNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_FileUploadNotFoundError' } } errorClasses.NotFound_FileUploadNotFoundError = NotFound_FileUploadNotFoundError
@@ -67,22 +67,22 @@ class File {
67
67
  return new FileUploadPart(partData)
68
68
  }
69
69
 
70
- static _completeUpload = async fileUploadPart => {
70
+ static _completeUpload = async firstFileUploadPart => {
71
71
  const params = {
72
72
  action: 'end',
73
- ref: fileUploadPart.ref,
73
+ ref: firstFileUploadPart.ref,
74
74
  }
75
75
 
76
- return Api.sendRequest(`/files/${encodeURIComponent(fileUploadPart.path)}`, 'POST', params)
76
+ return Api.sendRequest(`/files/${encodeURIComponent(firstFileUploadPart.path)}`, 'POST', params)
77
77
  }
78
78
 
79
79
  /**
80
80
  * @note see File.copy() for list of supported params
81
81
  */
82
82
  static uploadStream = async (destinationPath, readableStream, params) => {
83
- const fileUploadPart = await File._openUpload(destinationPath, params)
83
+ const firstFileUploadPart = await File._openUpload(destinationPath, params)
84
84
 
85
- if (!fileUploadPart) {
85
+ if (!firstFileUploadPart) {
86
86
  return
87
87
  }
88
88
 
@@ -91,28 +91,38 @@ class File {
91
91
  let part = 0
92
92
  let chunks = []
93
93
  let length = 0
94
+ const concurrentUploads = []
94
95
 
95
96
  readableStream.on('error', error => { reject(error) })
96
97
 
97
98
  readableStream.on('data', async chunk => {
98
99
  try {
99
- length += chunk.length
100
+ const nextLength = length + chunk.length
101
+ const excessLength = nextLength - firstFileUploadPart.partsize
102
+
103
+ const chunkBuffer = Buffer.from(chunk)
100
104
 
101
- if (length > fileUploadPart.partsize) {
105
+ if (excessLength > 0) {
102
106
  readableStream.pause()
103
107
 
108
+ const lastChunkForPart = chunkBuffer.subarray(0, excessLength)
109
+ const firstChunkForNextPart = chunkBuffer.subarray(excessLength)
110
+
111
+ chunks.push(lastChunkForPart)
112
+
104
113
  const buffer = Buffer.concat(chunks)
105
- const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, fileUploadPart)
114
+ const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, firstFileUploadPart)
106
115
 
107
- await Api.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer)
116
+ concurrentUploads.push(Api.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer))
108
117
 
109
- chunks = []
110
- length = 0
118
+ chunks = [firstChunkForNextPart]
119
+ length = 1
111
120
 
112
121
  readableStream.resume()
122
+ } else {
123
+ chunks.push(chunkBuffer)
124
+ length += chunk.length
113
125
  }
114
-
115
- chunks.push(Buffer.from(chunk))
116
126
  } catch (error) {
117
127
  reject(error)
118
128
  }
@@ -122,12 +132,14 @@ class File {
122
132
  try {
123
133
  if (chunks.length > 0) {
124
134
  const buffer = Buffer.concat(chunks)
125
- const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, fileUploadPart)
135
+ const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, firstFileUploadPart)
126
136
 
127
- await Api.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer)
137
+ concurrentUploads.push(Api.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer))
128
138
  }
129
139
 
130
- const response = await File._completeUpload(fileUploadPart)
140
+ await Promise.all(concurrentUploads)
141
+
142
+ const response = await File._completeUpload(firstFileUploadPart)
131
143
  const createdFile = new File(response.data)
132
144
 
133
145
  resolve(createdFile)