-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy paths3-object.js
41 lines (36 loc) · 955 Bytes
/
s3-object.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
33
34
35
36
37
38
39
40
41
"use strict";
const { pick, pickBy } = require("lodash");
class S3Object {
constructor(bucket, key, content, metadata) {
this.bucket = bucket;
this.key = key;
this.content = content;
this.metadata = pick(metadata, [
"cache-control",
"content-disposition",
"content-encoding",
"content-language",
"content-type",
"expires",
"website-redirect-location",
// instrinsic metadata determined when retrieving objects
"last-modified",
"etag",
"content-length"
]);
if (!this.metadata["content-type"]) {
this.metadata["content-type"] = "binary/octet-stream";
}
Object.assign(
this.metadata,
pickBy(metadata, (v, k) => k.startsWith("x-amz-meta-"))
);
}
get size() {
return Number(this.metadata["content-length"]);
}
get lastModifiedDate() {
return new Date(this.metadata["last-modified"]);
}
}
module.exports = S3Object;