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
-20
View File
@@ -1,20 +0,0 @@
'use strict';
exports = module.exports = chunk;
const assert = require('assert');
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;
}
+17 -2
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');
+2 -1
View File
@@ -7,7 +7,6 @@
'use strict';
const BoxError = require('../boxerror.js'),
chunk = require('../chunk.js');
common = require('./common.js'),
execSync = require('child_process').execSync,
expect = require('expect.js'),
@@ -24,6 +23,8 @@ const BoxError = require('../boxerror.js'),
safe = require('safetydance'),
settings = require('../settings.js');
const chunk = s3._chunk;
describe('Storage', function () {
const { setup, cleanup } = common;