inline chunk.js

This commit is contained in:
Girish Ramakrishnan
2022-04-15 09:25:54 -05:00
parent bdc9a0cbe3
commit 9a886111ad
3 changed files with 19 additions and 23 deletions

View File

@@ -22,14 +22,14 @@ exports = module.exports = {
// Used to mock AWS
_mockInject: mockInject,
_mockRestore: mockRestore
_mockRestore: mockRestore,
_chunk: chunk
};
const assert = require('assert'),
async = require('async'),
AwsSdk = require('aws-sdk'),
BoxError = require('../boxerror.js'),
chunk = require('../chunk.js'),
constants = require('../constants.js'),
DataLayout = require('../datalayout.js'),
debug = require('debug')('box:storage/s3'),
@@ -406,6 +406,21 @@ async function remove(apiConfig, filename) {
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, `Unable to remove ${deleteParams.Key}. error: ${error.message}`);
}
function chunk(array, size) {
assert(Array.isArray(array));
assert.strictEqual(typeof size, 'number');
const length = array.length;
if (!length) return [];
let index = 0, resIndex = 0, result = Array(Math.ceil(length / size));
for (; index < length; index += size) {
result[resIndex++] = array.slice(index, index+size);
}
return result;
}
async function removeDir(apiConfig, pathPrefix, progressCallback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof pathPrefix, 'string');