UNPKG

@cumulus/aws-client

Version:
45 lines 2.31 kB
"use strict"; // Utility functions to help with S3 multi-part uploads var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.uploadPartCopy = exports.abortMultipartUpload = exports.completeMultipartUpload = exports.createMultipartUpload = exports.createMultipartChunks = void 0; const range_1 = __importDefault(require("lodash/range")); const services_1 = require("../services"); const MB = 1024 * 1024; /** * Each part of a multi-part copy needs to specify a byte range to be copied. * This byte range has a starting byte and an ending byte (inclusive) that makes * up the part. The maximum allowed chunk size is 5368709120 bytes. * * This function takes a file size and an optional maxSize. It returns an array * of objects, each containing a `start` and an `end` value. These will make up * the ranges of the multi-part copy. * * From anecdotal testing, a chunk size of 250 MB seems to perform fairly well. * * https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html * * @param {number} objectSize - size of the object * @param {number} chunkSize - chunk size of the S3 multipart uploads * @returns {Promise<Array<Chunk>>} - array of chunks */ const createMultipartChunks = (objectSize, chunkSize = 250 * MB) => (0, range_1.default)(0, objectSize, chunkSize) .map((start) => ({ start, end: Math.min(start + chunkSize, objectSize) - 1, })); exports.createMultipartChunks = createMultipartChunks; const createMultipartUpload = async (params) => await (0, services_1.s3)().createMultipartUpload(params); exports.createMultipartUpload = createMultipartUpload; const completeMultipartUpload = async (params) => { const result = await (0, services_1.s3)().completeMultipartUpload(params); return result; }; exports.completeMultipartUpload = completeMultipartUpload; const abortMultipartUpload = async (params) => await (0, services_1.s3)().abortMultipartUpload(params); exports.abortMultipartUpload = abortMultipartUpload; const uploadPartCopy = async (params) => await (0, services_1.s3)().uploadPartCopy(params); exports.uploadPartCopy = uploadPartCopy; //# sourceMappingURL=S3MultipartUploads.js.map