@tus/s3-store
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -9,3 +9,14 @@ import fs from 'node:fs'; | ||
export type Options = { | ||
/** | ||
* The preferred part size for parts send to S3. Can not be lower than 5MiB or more than 5GiB. | ||
* The server calculates the optimal part size, which takes this size into account, | ||
* but may increase it to not exceed the S3 10K parts limit. | ||
*/ | ||
partSize?: number; | ||
/** | ||
* The minimal part size for parts. | ||
* Can be used to ensure that all non-trailing parts are exactly the same size. | ||
* Can not be lower than 5MiB or more than 5GiB. | ||
*/ | ||
minPartSize?: number; | ||
useTags?: boolean; | ||
@@ -33,3 +44,3 @@ maxConcurrentPartUploads?: number; | ||
maxMultipartParts: 10000; | ||
minPartSize: 5242880; | ||
minPartSize: number; | ||
maxUploadSize: 5497558138880; | ||
@@ -36,0 +47,0 @@ constructor(options: Options); |
@@ -86,3 +86,3 @@ "use strict"; | ||
this.maxUploadSize = 5497558138880; // 5TiB | ||
const { partSize, s3ClientConfig } = options; | ||
const { partSize, minPartSize, s3ClientConfig } = options; | ||
const { bucket, ...restS3ClientConfig } = s3ClientConfig; | ||
@@ -98,2 +98,5 @@ this.extensions = [ | ||
this.preferredPartSize = partSize || 8 * 1024 * 1024; | ||
if (minPartSize) { | ||
this.minPartSize = minPartSize; | ||
} | ||
this.expirationPeriodInMilliseconds = options.expirationPeriodInMilliseconds ?? 0; | ||
@@ -170,3 +173,3 @@ this.useTags = options.useTags ?? true; | ||
id, | ||
size: file.size ? Number.parseInt(file.size, 10) : undefined, | ||
size: Number.isFinite(file.size) ? Number.parseInt(file.size, 10) : undefined, | ||
offset: Number.parseInt(file.offset, 10), | ||
@@ -442,3 +445,4 @@ metadata: file.metadata, | ||
} | ||
return optimalPartSize; | ||
// Always ensure the part size is at least minPartSize | ||
return Math.max(optimalPartSize, this.minPartSize); | ||
} | ||
@@ -445,0 +449,0 @@ /** |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@tus/s3-store", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "AWS S3 store for @tus/server", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
@@ -16,2 +16,3 @@ # `@tus/s3-store` | ||
- [Example: using `credentials` to fetch credentials inside a AWS container](#example-using-credentials-to-fetch-credentials-inside-a-aws-container) | ||
- [Example: use with Cloudflare R2](#example-use-with-cloudflare-r2) | ||
- [Types](#types) | ||
@@ -65,6 +66,16 @@ - [Compatibility](#compatibility) | ||
The preferred part size for parts send to S3. Can not be lower than 5MiB or more than | ||
The **preferred** part size for parts send to S3. Can not be lower than 5MiB or more than | ||
5GiB. The server calculates the optimal part size, which takes this size into account, but | ||
may increase it to not exceed the S3 10K parts limit. | ||
#### `options.minPartSize` | ||
The minimal part size for parts. | ||
Can be used to ensure that all non-trailing parts are exactly the same size | ||
by setting `partSize` and `minPartSize` to the same value. | ||
Can not be lower than 5MiB or more than 5GiB. | ||
The server calculates the optimal part size, which takes this size into account, but | ||
may increase it to not exceed the S3 10K parts limit. | ||
#### `options.s3ClientConfig` | ||
@@ -187,3 +198,3 @@ | ||
const {Server} = require('@tus/server') | ||
const {FileStore} = require('@tus/s3-store') | ||
const {S3Store} = require('@tus/s3-store') | ||
@@ -205,2 +216,18 @@ const s3Store = new S3Store({ | ||
### Example: use with Cloudflare R2 | ||
`@tus/s3-store` can be used with all S3-compatible storage solutions, including Cloudflare R2. | ||
However R2 requires that all non-trailing parts are _exactly_ the same size. | ||
This can be achieved by setting `partSize` and `minPartSize` to the same value. | ||
```ts | ||
// ... | ||
const s3Store = new S3Store({ | ||
partSize: 8 * 1024 * 1024, | ||
minPartSize: 8 * 1024 * 1024, | ||
// ... | ||
}) | ||
``` | ||
## Types | ||
@@ -207,0 +234,0 @@ |
@@ -28,6 +28,14 @@ import os from 'node:os' | ||
export type Options = { | ||
// The preferred part size for parts send to S3. Can not be lower than 5MiB or more than 5GiB. | ||
// The server calculates the optimal part size, which takes this size into account, | ||
// but may increase it to not exceed the S3 10K parts limit. | ||
/** | ||
* The preferred part size for parts send to S3. Can not be lower than 5MiB or more than 5GiB. | ||
* The server calculates the optimal part size, which takes this size into account, | ||
* but may increase it to not exceed the S3 10K parts limit. | ||
*/ | ||
partSize?: number | ||
/** | ||
* The minimal part size for parts. | ||
* Can be used to ensure that all non-trailing parts are exactly the same size. | ||
* Can not be lower than 5MiB or more than 5GiB. | ||
*/ | ||
minPartSize?: number | ||
useTags?: boolean | ||
@@ -94,3 +102,3 @@ maxConcurrentPartUploads?: number | ||
public maxMultipartParts = 10_000 as const | ||
public minPartSize = 5_242_880 as const // 5MiB | ||
public minPartSize = 5_242_880 // 5MiB | ||
public maxUploadSize = 5_497_558_138_880 as const // 5TiB | ||
@@ -100,3 +108,3 @@ | ||
super() | ||
const {partSize, s3ClientConfig} = options | ||
const {partSize, minPartSize, s3ClientConfig} = options | ||
const {bucket, ...restS3ClientConfig} = s3ClientConfig | ||
@@ -112,2 +120,5 @@ this.extensions = [ | ||
this.preferredPartSize = partSize || 8 * 1024 * 1024 | ||
if (minPartSize) { | ||
this.minPartSize = minPartSize | ||
} | ||
this.expirationPeriodInMilliseconds = options.expirationPeriodInMilliseconds ?? 0 | ||
@@ -192,3 +203,3 @@ this.useTags = options.useTags ?? true | ||
id, | ||
size: file.size ? Number.parseInt(file.size, 10) : undefined, | ||
size: Number.isFinite(file.size) ? Number.parseInt(file.size, 10) : undefined, | ||
offset: Number.parseInt(file.offset, 10), | ||
@@ -517,3 +528,4 @@ metadata: file.metadata, | ||
return optimalPartSize | ||
// Always ensure the part size is at least minPartSize | ||
return Math.max(optimalPartSize, this.minPartSize) | ||
} | ||
@@ -520,0 +532,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
89603
1502
262