Skip to content

Commit b71f8b0

Browse files
Address PR comments
1 parent c0493dd commit b71f8b0

File tree

2 files changed

+52
-54
lines changed

2 files changed

+52
-54
lines changed

lib/Open/index.js

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,98 @@
1-
const fs = require('graceful-fs');
2-
const directory = require('./directory');
3-
const Stream = require('stream');
4-
const { GetObjectCommand, HeadObjectCommand } = require('@aws-sdk/client-s3');
1+
const fs = require("graceful-fs");
2+
const directory = require("./directory");
3+
const Stream = require("stream");
54

65
module.exports = {
7-
buffer: function(buffer, options) {
6+
buffer: function (buffer, options) {
87
const source = {
9-
stream: function(offset, length) {
8+
stream: function (offset, length) {
109
const stream = Stream.PassThrough();
1110
const end = length ? offset + length : undefined;
1211
stream.end(buffer.slice(offset, end));
1312
return stream;
1413
},
15-
size: function() {
14+
size: function () {
1615
return Promise.resolve(buffer.length);
17-
}
16+
},
1817
};
1918
return directory(source, options);
2019
},
21-
file: function(filename, options) {
20+
file: function (filename, options) {
2221
const source = {
23-
stream: function(start, length) {
22+
stream: function (start, length) {
2423
const end = length ? start + length : undefined;
25-
return fs.createReadStream(filename, {start, end});
24+
return fs.createReadStream(filename, { start, end });
2625
},
27-
size: function() {
28-
return new Promise(function(resolve, reject) {
29-
fs.stat(filename, function(err, d) {
30-
if (err)
31-
reject(err);
32-
else
33-
resolve(d.size);
26+
size: function () {
27+
return new Promise(function (resolve, reject) {
28+
fs.stat(filename, function (err, d) {
29+
if (err) reject(err);
30+
else resolve(d.size);
3431
});
3532
});
36-
}
33+
},
3734
};
3835
return directory(source, options);
3936
},
4037

41-
url: function(request, params, options) {
42-
if (typeof params === 'string')
43-
params = {url: params};
44-
if (!params.url)
45-
throw 'URL missing';
38+
url: function (request, params, options) {
39+
if (typeof params === "string") params = { url: params };
40+
if (!params.url) throw "URL missing";
4641
params.headers = params.headers || {};
4742

4843
const source = {
49-
stream : function(offset, length) {
44+
stream: function (offset, length) {
5045
const options = Object.create(params);
51-
const end = length ? offset + length : '';
46+
const end = length ? offset + length : "";
5247
options.headers = Object.create(params.headers);
53-
options.headers.range = 'bytes='+offset+'-' + end;
48+
options.headers.range = "bytes=" + offset + "-" + end;
5449
return request(options);
5550
},
56-
size: function() {
57-
return new Promise(function(resolve, reject) {
51+
size: function () {
52+
return new Promise(function (resolve, reject) {
5853
const req = request(params);
59-
req.on('response', function(d) {
60-
req.abort();
61-
if (!d.headers['content-length'])
62-
reject(new Error('Missing content length header'));
63-
else
64-
resolve(d.headers['content-length']);
65-
}).on('error', reject);
54+
req
55+
.on("response", function (d) {
56+
req.abort();
57+
if (!d.headers["content-length"])
58+
reject(new Error("Missing content length header"));
59+
else resolve(d.headers["content-length"]);
60+
})
61+
.on("error", reject);
6662
});
67-
}
63+
},
6864
};
6965

7066
return directory(source, options);
7167
},
7268

73-
s3 : function(client, params, options) {
69+
s3: function (client, params, options) {
7470
const source = {
75-
size: function() {
76-
return new Promise(function(resolve, reject) {
77-
client.headObject(params, function(err, d) {
78-
if (err)
79-
reject(err);
80-
else
81-
resolve(d.ContentLength);
71+
size: function () {
72+
return new Promise(function (resolve, reject) {
73+
client.headObject(params, function (err, d) {
74+
if (err) reject(err);
75+
else resolve(d.ContentLength);
8276
});
8377
});
8478
},
85-
stream: function(offset, length) {
79+
stream: function (offset, length) {
8680
const d = {};
87-
for (const key in params)
88-
d[key] = params[key];
89-
const end = length ? offset + length : '';
90-
d.Range = 'bytes='+offset+'-' + end;
81+
for (const key in params) d[key] = params[key];
82+
const end = length ? offset + length : "";
83+
d.Range = "bytes=" + offset + "-" + end;
9184
return client.getObject(d).createReadStream();
92-
}
85+
},
9386
};
9487

9588
return directory(source, options);
9689
},
9790
s3_v3: function (client, params, options) {
91+
const {
92+
GetObjectCommand,
93+
HeadObjectCommand,
94+
} = require("@aws-sdk/client-s3");
95+
9896
const source = {
9997
size: async () => {
10098
const head = await client.send(
@@ -130,7 +128,7 @@ module.exports = {
130128

131129
return directory(source, options);
132130
},
133-
custom: function(source, options) {
131+
custom: function (source, options) {
134132
return directory(source, options);
135-
}
133+
},
136134
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"tap": "^12.7.0",
4242
"temp": ">= 0.4.0 < 1"
4343
},
44-
"peerDependencies": {
44+
"optionalDependencies": {
4545
"@aws-sdk/client-s3": "^3.0.0"
4646
},
4747
"directories": {

0 commit comments

Comments
 (0)