Skip to content

Commit

Permalink
fix: rename _createBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
beajer committed Mar 16, 2021
1 parent bfdfa89 commit 9fd9d80
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/browser/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ proto._resumeMultipart = async function _resumeMultipart(checkpoint, options) {
try {
if (!self.isCancel()) {
const pi = partOffs[partNo - 1];
const content = await self._createStream(file, pi.start, pi.end);
const content = await self._createBuffer(file, pi.start, pi.end);
const data = {
content,
size: pi.end - pi.start
Expand Down Expand Up @@ -303,15 +303,15 @@ WebFileReadStream.prototype._read = function _read(size) {
}
};

proto._createStream = async function _createStream(file, start, end) {
proto._createBuffer = async function _createBuffer(file, start, end) {
if (isBlob(file) || isFile(file)) {
const _file = file.slice(start, end);
const fileContent = await _file.arrayBuffer();
return Buffer.from(fileContent);
} else if (isBuffer(file)) {
return file.subarray(start, end);
} else {
throw new Error('_createStream requires File/Blob/Buffer.');
throw new Error('_createBuffer requires File/Blob/Buffer.');
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/browser/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ proto.put = async function put(name, file, options) {
}
}

content = await this._createStream(file, 0, file.size);
content = await this._createBuffer(file, 0, file.size);
options.contentLength = await this._getFileSize(file);
} else {
throw new TypeError('Must provide Buffer/Blob/File for put.');
Expand Down
5 changes: 3 additions & 2 deletions lib/common/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@ proto.initMultipartUpload = async function initMultipartUpload(name, options) {
* @param {Object} options
*/
proto.uploadPart = async function uploadPart(name, uploadId, partNo, file, start, end, options) {
const mayBeBufferOrStream = await this._createStream(file, start, end);
const data = {
size: end - start
};
const isBrowserEnv = process && process.browser;
isBrowserEnv ? (data.content = mayBeBufferOrStream) : (data.stream = mayBeBufferOrStream);
isBrowserEnv
? (data.content = await this._createBuffer(file, start, end))
: (data.stream = await this._createStream(file, start, end));
return await this._uploadPart(name, uploadId, partNo, data, options);
};

Expand Down

0 comments on commit 9fd9d80

Please sign in to comment.