@constructive-io/s3-streamer 2.44.5 → 2.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -22
- package/esm/index.js +0 -2
- package/esm/streamer.js +2 -9
- package/index.d.ts +0 -2
- package/index.js +1 -3
- package/package.json +4 -5
- package/streamer.d.ts +4 -7
- package/streamer.js +2 -12
- package/esm/s3.js +0 -10
- package/s3.d.ts +0 -11
- package/s3.js +0 -13
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ Stream uploads to S3
|
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
37
|
import Streamer from '@constructive-io/s3-streamer';
|
|
38
|
-
const streamer = new Streamer(
|
|
38
|
+
const streamer = new Streamer({ client, defaultBucket })
|
|
39
39
|
const readStream = createReadStream(filename);
|
|
40
40
|
const results = await streamer.upload({
|
|
41
41
|
readStream,
|
|
@@ -91,8 +91,9 @@ The upload methods return a detailed payload with upload results and file metada
|
|
|
91
91
|
If you don't want to use the `Streamer` class you can use the utils directly:
|
|
92
92
|
|
|
93
93
|
```js
|
|
94
|
-
import {
|
|
95
|
-
|
|
94
|
+
import { createS3Client } from '@constructive-io/s3-utils';
|
|
95
|
+
import { upload } from '@constructive-io/s3-streamer';
|
|
96
|
+
const client = createS3Client(opts)
|
|
96
97
|
const readStream = createReadStream(filename);
|
|
97
98
|
const results = await upload({
|
|
98
99
|
client,
|
|
@@ -110,9 +111,12 @@ const results = await upload({
|
|
|
110
111
|
```js
|
|
111
112
|
const streamer = new Streamer({
|
|
112
113
|
defaultBucket: 'my-bucket',
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
client: createS3Client({
|
|
115
|
+
provider: 's3',
|
|
116
|
+
region: 'us-east-1',
|
|
117
|
+
accessKeyId: process.env.STORAGE_ACCESS_KEY_ID,
|
|
118
|
+
secretAccessKey: process.env.STORAGE_SECRET_ACCESS_KEY
|
|
119
|
+
})
|
|
116
120
|
});
|
|
117
121
|
```
|
|
118
122
|
|
|
@@ -121,10 +125,13 @@ const streamer = new Streamer({
|
|
|
121
125
|
```js
|
|
122
126
|
const streamer = new Streamer({
|
|
123
127
|
defaultBucket: 'my-bucket',
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
client: createS3Client({
|
|
129
|
+
provider: 'minio',
|
|
130
|
+
region: 'us-east-1',
|
|
131
|
+
accessKeyId: process.env.STORAGE_ACCESS_KEY_ID,
|
|
132
|
+
secretAccessKey: process.env.STORAGE_SECRET_ACCESS_KEY,
|
|
133
|
+
endpoint: 'http://localhost:9000'
|
|
134
|
+
})
|
|
128
135
|
});
|
|
129
136
|
```
|
|
130
137
|
|
|
@@ -135,12 +142,9 @@ const streamer = new Streamer({
|
|
|
135
142
|
#### Constructor Options
|
|
136
143
|
|
|
137
144
|
```typescript
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
awsAccessKey: string; // AWS access key ID
|
|
142
|
-
minioEndpoint?: string; // Optional: MinIO/S3-compatible endpoint
|
|
143
|
-
defaultBucket: string; // Default bucket for uploads
|
|
145
|
+
{
|
|
146
|
+
client: S3Client; // S3 client for the resolved object store (see createS3Client in @constructive-io/s3-utils)
|
|
147
|
+
defaultBucket?: string; // Bucket used when a call names none
|
|
144
148
|
}
|
|
145
149
|
```
|
|
146
150
|
|
|
@@ -172,14 +176,16 @@ streamer.destroy();
|
|
|
172
176
|
If you prefer functional programming over classes:
|
|
173
177
|
|
|
174
178
|
```js
|
|
175
|
-
import {
|
|
179
|
+
import { createS3Client } from '@constructive-io/s3-utils';
|
|
180
|
+
import { upload } from '@constructive-io/s3-streamer';
|
|
176
181
|
|
|
177
182
|
// Create S3 client
|
|
178
|
-
const client =
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
const client = createS3Client({
|
|
184
|
+
provider: 'minio',
|
|
185
|
+
region: 'us-east-1',
|
|
186
|
+
accessKeyId: process.env.STORAGE_ACCESS_KEY_ID,
|
|
187
|
+
secretAccessKey: process.env.STORAGE_SECRET_ACCESS_KEY,
|
|
188
|
+
endpoint: 'http://localhost:9000' // omit for AWS S3
|
|
183
189
|
});
|
|
184
190
|
|
|
185
191
|
// Upload file
|
package/esm/index.js
CHANGED
package/esm/streamer.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { streamContentType } from '@constructive-io/content-type-stream';
|
|
2
|
-
import getS3 from './s3';
|
|
3
2
|
import { upload as streamUpload, uploadWithContentType as streamUploadWithContentType, } from './utils';
|
|
4
3
|
export class Streamer {
|
|
5
4
|
s3;
|
|
6
5
|
defaultBucket;
|
|
7
|
-
constructor({
|
|
8
|
-
this.s3 =
|
|
9
|
-
awsRegion,
|
|
10
|
-
awsSecretKey,
|
|
11
|
-
awsAccessKey,
|
|
12
|
-
endpoint,
|
|
13
|
-
provider
|
|
14
|
-
});
|
|
6
|
+
constructor({ client, defaultBucket }) {
|
|
7
|
+
this.s3 = client;
|
|
15
8
|
this.defaultBucket = defaultBucket;
|
|
16
9
|
}
|
|
17
10
|
async upload({ readStream, filename, key, bucket = this.defaultBucket }) {
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -17,9 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.Streamer =
|
|
21
|
-
const s3_1 = __importDefault(require("./s3"));
|
|
22
|
-
exports.getClient = s3_1.default;
|
|
20
|
+
exports.Streamer = void 0;
|
|
23
21
|
const streamer_1 = __importDefault(require("./streamer"));
|
|
24
22
|
exports.Streamer = streamer_1.default;
|
|
25
23
|
__exportStar(require("./utils"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/s3-streamer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.45.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "stream files to s3",
|
|
6
6
|
"main": "index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test:watch": "jest --watch"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@pgpmjs/env": "^2.
|
|
32
|
+
"@pgpmjs/env": "^2.47.0",
|
|
33
33
|
"glob": "^13.0.6",
|
|
34
34
|
"makage": "^0.8.0"
|
|
35
35
|
},
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
"@aws-sdk/client-s3": "^3.1052.0",
|
|
38
38
|
"@aws-sdk/lib-storage": "^3.1052.0",
|
|
39
39
|
"@constructive-io/content-type-stream": "^2.32.0",
|
|
40
|
-
"@constructive-io/s3-utils": "^2.34.0"
|
|
41
|
-
"@pgpmjs/types": "^2.56.2"
|
|
40
|
+
"@constructive-io/s3-utils": "^2.34.0"
|
|
42
41
|
},
|
|
43
42
|
"keywords": [
|
|
44
43
|
"s3",
|
|
@@ -48,5 +47,5 @@
|
|
|
48
47
|
"minio",
|
|
49
48
|
"constructive"
|
|
50
49
|
],
|
|
51
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "1f3501d518e175803a1a3372cf9249922d82bfe5"
|
|
52
51
|
}
|
package/streamer.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
1
2
|
import { streamContentType } from '@constructive-io/content-type-stream';
|
|
2
|
-
import type { BucketProvider } from '@pgpmjs/types';
|
|
3
3
|
import type { Readable } from 'stream';
|
|
4
4
|
import { type AsyncUploadResult } from './utils';
|
|
5
5
|
interface StreamerOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
awsAccessKey: string;
|
|
9
|
-
endpoint?: string;
|
|
10
|
-
provider?: BucketProvider;
|
|
6
|
+
/** Client for the object store the caller resolved (see `createS3Client` in `@constructive-io/s3-utils`). */
|
|
7
|
+
client: S3Client;
|
|
11
8
|
/**
|
|
12
9
|
* Bucket used when a call does not name one. Optional: a caller that resolves
|
|
13
10
|
* the bucket per upload (tenant-resolved storage) has no deployment-wide
|
|
@@ -35,7 +32,7 @@ interface UploadWithContentTypeParams {
|
|
|
35
32
|
export declare class Streamer {
|
|
36
33
|
private s3;
|
|
37
34
|
private defaultBucket?;
|
|
38
|
-
constructor({
|
|
35
|
+
constructor({ client, defaultBucket }: StreamerOptions);
|
|
39
36
|
upload({ readStream, filename, key, bucket }: UploadParams): Promise<AsyncUploadResult>;
|
|
40
37
|
uploadWithContentType({ readStream, contentType, key, bucket, magic, }: UploadWithContentTypeParams): Promise<AsyncUploadResult>;
|
|
41
38
|
detectContentType({ readStream, filename, peekBytes, }: {
|
package/streamer.js
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Streamer = void 0;
|
|
7
4
|
const content_type_stream_1 = require("@constructive-io/content-type-stream");
|
|
8
|
-
const s3_1 = __importDefault(require("./s3"));
|
|
9
5
|
const utils_1 = require("./utils");
|
|
10
6
|
class Streamer {
|
|
11
7
|
s3;
|
|
12
8
|
defaultBucket;
|
|
13
|
-
constructor({
|
|
14
|
-
this.s3 =
|
|
15
|
-
awsRegion,
|
|
16
|
-
awsSecretKey,
|
|
17
|
-
awsAccessKey,
|
|
18
|
-
endpoint,
|
|
19
|
-
provider
|
|
20
|
-
});
|
|
9
|
+
constructor({ client, defaultBucket }) {
|
|
10
|
+
this.s3 = client;
|
|
21
11
|
this.defaultBucket = defaultBucket;
|
|
22
12
|
}
|
|
23
13
|
async upload({ readStream, filename, key, bucket = this.defaultBucket }) {
|
package/esm/s3.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createS3Client } from '@constructive-io/s3-utils';
|
|
2
|
-
export default function getS3(opts) {
|
|
3
|
-
return createS3Client({
|
|
4
|
-
provider: opts.provider || 'minio',
|
|
5
|
-
region: opts.awsRegion,
|
|
6
|
-
accessKeyId: opts.awsAccessKey,
|
|
7
|
-
secretAccessKey: opts.awsSecretKey,
|
|
8
|
-
...(opts.endpoint ? { endpoint: opts.endpoint } : {}),
|
|
9
|
-
});
|
|
10
|
-
}
|
package/s3.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { S3Client } from '@aws-sdk/client-s3';
|
|
2
|
-
import type { BucketProvider } from '@pgpmjs/types';
|
|
3
|
-
interface S3Options {
|
|
4
|
-
awsAccessKey: string;
|
|
5
|
-
awsSecretKey: string;
|
|
6
|
-
awsRegion: string;
|
|
7
|
-
endpoint?: string;
|
|
8
|
-
provider?: BucketProvider;
|
|
9
|
-
}
|
|
10
|
-
export default function getS3(opts: S3Options): S3Client;
|
|
11
|
-
export {};
|
package/s3.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = getS3;
|
|
4
|
-
const s3_utils_1 = require("@constructive-io/s3-utils");
|
|
5
|
-
function getS3(opts) {
|
|
6
|
-
return (0, s3_utils_1.createS3Client)({
|
|
7
|
-
provider: opts.provider || 'minio',
|
|
8
|
-
region: opts.awsRegion,
|
|
9
|
-
accessKeyId: opts.awsAccessKey,
|
|
10
|
-
secretAccessKey: opts.awsSecretKey,
|
|
11
|
-
...(opts.endpoint ? { endpoint: opts.endpoint } : {}),
|
|
12
|
-
});
|
|
13
|
-
}
|