Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for @aws-sdk version 3 #325

Merged
merged 6 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions lib/Open/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('graceful-fs');
const directory = require('./directory');
const Stream = require('stream');
const { GetObjectCommand, HeadObjectCommand } = require('@aws-sdk/client-s3');
alice-was-here marked this conversation as resolved.
Show resolved Hide resolved

module.exports = {
buffer: function(buffer, options) {
Expand Down Expand Up @@ -93,7 +94,42 @@ module.exports = {

return directory(source, options);
},
s3_v3: function (client, params, options) {
const source = {
size: async () => {
const head = await client.send(
new HeadObjectCommand({
Bucket: params.Bucket,
Key: params.Key,
})
);

return head.ContentLength ?? 0;
alice-was-here marked this conversation as resolved.
Show resolved Hide resolved
},
stream: (offset, length) => {
const stream = Stream.PassThrough();
const end = length ? offset + length : "";
client
.send(
new GetObjectCommand({
Bucket: params.Bucket,
Key: params.Key,
Range: `bytes=${offset}-${end}`,
})
)
.then((response) => {
response.Body.pipe(stream);
})
.catch((error) => {
stream.emit("error", error);
});

return stream;
},
};

return directory(source, options);
},
custom: function(source, options) {
return directory(source, options);
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"tap": "^12.7.0",
"temp": ">= 0.4.0 < 1"
},
"peerDependencies": {
"@aws-sdk/client-s3": "^3.0.0"
alice-was-here marked this conversation as resolved.
Show resolved Hide resolved
},
"directories": {
"example": "examples",
"test": "test"
Expand Down
Loading