-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingest_buckets.js
32 lines (27 loc) · 930 Bytes
/
ingest_buckets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const batch = require('./batch');
function ingest_buckets(options, cb) {
if (!options.prefix) {
options.prefix = `test-bucket-${new Date().toISOString().replace(/[:.]/g, '-').toLowerCase()}`;
}
const obj = batch.create(options);
batch.showOptions(obj);
console.log(`
`);
const ingestOp = (s3, n, endSuccess, endError) => {
const compMask = Buffer.alloc(6).fill('0').toString();
const suffix = `${compMask}${n}`.slice(-compMask.length);
const bucketName = `${options.prefix}-${suffix}`;
s3.createBucket({
Bucket: bucketName,
}, err => {
if (err) {
console.error(`error during "PUT /${bucketName}":`,
err.message);
return endError();
}
return endSuccess();
});
};
batch.run(obj, ingestOp, cb);
}
module.exports = ingest_buckets;