Skip to content

Commit

Permalink
Add node16 + tests, make import conditional, revert formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-was-here committed Jul 9, 2024
1 parent 5d05b72 commit 3927030
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Open/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('graceful-fs');
const directory = require('./directory');
const Stream = require('stream');
const { GetObjectCommand, HeadObjectCommand } = require('@aws-sdk/client-s3');

module.exports = {
buffer: function(buffer, options) {
Expand Down Expand Up @@ -95,6 +94,7 @@ module.exports = {
return directory(source, options);
},
s3_v3: function (client, params, options) {
const { GetObjectCommand, HeadObjectCommand } = require('@aws-sdk/client-s3');
const source = {
size: async () => {
const head = await client.send(
Expand All @@ -104,7 +104,11 @@ module.exports = {
})
);

return head.ContentLength ?? 0;
if(!head.ContentLength) {
return 0;
}

return head.ContentLength;
},
stream: (offset, length) => {
const stream = Stream.PassThrough();
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"devDependencies": {
"@eslint/js": "^9.2.0",
"aws-sdk": "^2.1636.0",
"@aws-sdk/client-s3": "^3.0.0",
"dirdiff": ">= 0.0.1 < 1",
"eslint": "^9.2.0",
"globals": "^15.2.0",
Expand Down
25 changes: 25 additions & 0 deletions test/openS3_v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const test = require('tap').test;
const fs = require('fs');
const path = require('path');
const unzip = require('../unzip');

const version = +process.version.replace('v', '').split('.')[0];

test("get content of a single file entry out of a zip", { skip: version < 16 }, function(t) {
const { S3Client } = require('@aws-sdk/client-s3');
const client = new S3Client({ region: 'us-east-1' });

return unzip.Open.s3_v3(client, { Bucket: 'unzipper', Key: 'archive.zip' })
.then(function(d) {
const file = d.files.filter(function(file) {
return file.path == 'file.txt';
})[0];

return file.buffer()
.then(function(str) {
const fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8');
t.equal(str.toString(), fileStr);
t.end();
});
});
});

0 comments on commit 3927030

Please sign in to comment.