@tus/s3-store
Advanced tools
Comparing version 1.6.2 to 1.7.0
@@ -0,5 +1,9 @@ | ||
import fs from 'node:fs'; | ||
import stream from 'node:stream'; | ||
import { type S3ClientConfig } from '@aws-sdk/client-s3'; | ||
import type { Readable } from 'node:stream'; | ||
import type AWS from '@aws-sdk/client-s3'; | ||
import { S3, type S3ClientConfig } from '@aws-sdk/client-s3'; | ||
import { DataStore, Upload, type KvStore } from '@tus/utils'; | ||
type Options = { | ||
import { Semaphore } from '@shopify/semaphore'; | ||
export type Options = { | ||
partSize?: number; | ||
@@ -20,9 +24,9 @@ useTags?: boolean; | ||
export declare class S3Store extends DataStore { | ||
private bucket; | ||
private cache; | ||
private client; | ||
private preferredPartSize; | ||
private expirationPeriodInMilliseconds; | ||
private useTags; | ||
private partUploadSemaphore; | ||
protected bucket: string; | ||
protected cache: KvStore<MetadataValue>; | ||
protected client: S3; | ||
protected preferredPartSize: number; | ||
protected expirationPeriodInMilliseconds: number; | ||
protected useTags: boolean; | ||
protected partUploadSemaphore: Semaphore; | ||
maxMultipartParts: 10000; | ||
@@ -40,4 +44,4 @@ minPartSize: 5242880; | ||
*/ | ||
private saveMetadata; | ||
private completeMetadata; | ||
protected saveMetadata(upload: Upload, uploadId: string): Promise<void>; | ||
protected completeMetadata(upload: Upload): Promise<void>; | ||
/** | ||
@@ -48,15 +52,21 @@ * Retrieves upload metadata previously saved in `${file_id}.info`. | ||
*/ | ||
private getMetadata; | ||
private infoKey; | ||
private partKey; | ||
private uploadPart; | ||
private uploadIncompletePart; | ||
private downloadIncompletePart; | ||
private getIncompletePart; | ||
private getIncompletePartSize; | ||
private deleteIncompletePart; | ||
protected getMetadata(id: string): Promise<MetadataValue>; | ||
protected infoKey(id: string): string; | ||
protected partKey(id: string, isIncomplete?: boolean): string; | ||
protected uploadPart(metadata: MetadataValue, readStream: fs.ReadStream | Readable, partNumber: number): Promise<string>; | ||
protected uploadIncompletePart(id: string, readStream: fs.ReadStream | Readable): Promise<string>; | ||
protected downloadIncompletePart(id: string): Promise<{ | ||
size: number; | ||
path: string; | ||
createReader: (options: { | ||
cleanUpOnEnd: boolean; | ||
}) => fs.ReadStream; | ||
} | undefined>; | ||
protected getIncompletePart(id: string): Promise<Readable | undefined>; | ||
protected getIncompletePartSize(id: string): Promise<number | undefined>; | ||
protected deleteIncompletePart(id: string): Promise<void>; | ||
/** | ||
* Uploads a stream to s3 using multiple parts | ||
*/ | ||
private uploadParts; | ||
protected uploadParts(metadata: MetadataValue, readStream: stream.Readable, currentPartNumber: number, offset: number): Promise<number>; | ||
/** | ||
@@ -66,3 +76,3 @@ * Completes a multipart upload on S3. | ||
*/ | ||
private finishMultipartUpload; | ||
protected finishMultipartUpload(metadata: MetadataValue, parts: Array<AWS.Part>): Promise<string | undefined>; | ||
/** | ||
@@ -72,8 +82,8 @@ * Gets the number of complete parts/chunks already uploaded to S3. | ||
*/ | ||
private retrieveParts; | ||
protected retrieveParts(id: string, partNumberMarker?: string): Promise<Array<AWS.Part>>; | ||
/** | ||
* Removes cached data for a given file. | ||
*/ | ||
private clearCache; | ||
private calcOptimalPartSize; | ||
protected clearCache(id: string): Promise<void>; | ||
protected calcOptimalPartSize(size?: number): number; | ||
/** | ||
@@ -96,5 +106,4 @@ * Creates a multipart upload on S3 attaching any metadata to it. | ||
deleteExpired(): Promise<number>; | ||
private uniqueTmpFileName; | ||
protected uniqueTmpFileName(template: string): Promise<string>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@tus/s3-store", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"description": "AWS S3 store for @tus/server", | ||
@@ -22,5 +22,5 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "^3.703.0", | ||
"@aws-sdk/client-s3": "^3.717.0", | ||
"@shopify/semaphore": "^3.1.0", | ||
"@tus/utils": "^0.5.0", | ||
"@tus/utils": "^0.5.1", | ||
"debug": "^4.3.4", | ||
@@ -34,3 +34,3 @@ "multistream": "^4.1.0" | ||
"@types/node": "^22.10.1", | ||
"mocha": "^10.4.0", | ||
"mocha": "^11.0.1", | ||
"should": "^13.2.3" | ||
@@ -37,0 +37,0 @@ }, |
@@ -27,3 +27,3 @@ import os from 'node:os' | ||
type Options = { | ||
export type Options = { | ||
// The preferred part size for parts send to S3. Can not be lower than 5MiB or more than 5GiB. | ||
@@ -86,9 +86,9 @@ // The server calculates the optimal part size, which takes this size into account, | ||
export class S3Store extends DataStore { | ||
private bucket: string | ||
private cache: KvStore<MetadataValue> | ||
private client: S3 | ||
private preferredPartSize: number | ||
private expirationPeriodInMilliseconds = 0 | ||
private useTags = true | ||
private partUploadSemaphore: Semaphore | ||
protected bucket: string | ||
protected cache: KvStore<MetadataValue> | ||
protected client: S3 | ||
protected preferredPartSize: number | ||
protected expirationPeriodInMilliseconds = 0 | ||
protected useTags = true | ||
protected partUploadSemaphore: Semaphore | ||
public maxMultipartParts = 10_000 as const | ||
@@ -136,3 +136,3 @@ public minPartSize = 5_242_880 as const // 5MiB | ||
*/ | ||
private async saveMetadata(upload: Upload, uploadId: string) { | ||
protected async saveMetadata(upload: Upload, uploadId: string) { | ||
log(`[${upload.id}] saving metadata`) | ||
@@ -152,3 +152,3 @@ await this.client.putObject({ | ||
private async completeMetadata(upload: Upload) { | ||
protected async completeMetadata(upload: Upload) { | ||
if (!this.shouldUseExpirationTags()) { | ||
@@ -176,3 +176,3 @@ return | ||
*/ | ||
private async getMetadata(id: string): Promise<MetadataValue> { | ||
protected async getMetadata(id: string): Promise<MetadataValue> { | ||
const cached = await this.cache.get(id) | ||
@@ -204,7 +204,7 @@ if (cached) { | ||
private infoKey(id: string) { | ||
protected infoKey(id: string) { | ||
return `${id}.info` | ||
} | ||
private partKey(id: string, isIncomplete = false) { | ||
protected partKey(id: string, isIncomplete = false) { | ||
if (isIncomplete) { | ||
@@ -221,3 +221,3 @@ id += '.part' | ||
private async uploadPart( | ||
protected async uploadPart( | ||
metadata: MetadataValue, | ||
@@ -238,3 +238,3 @@ readStream: fs.ReadStream | Readable, | ||
private async uploadIncompletePart( | ||
protected async uploadIncompletePart( | ||
id: string, | ||
@@ -253,3 +253,3 @@ readStream: fs.ReadStream | Readable | ||
private async downloadIncompletePart(id: string) { | ||
protected async downloadIncompletePart(id: string) { | ||
const incompletePart = await this.getIncompletePart(id) | ||
@@ -313,3 +313,3 @@ | ||
private async getIncompletePart(id: string): Promise<Readable | undefined> { | ||
protected async getIncompletePart(id: string): Promise<Readable | undefined> { | ||
try { | ||
@@ -330,3 +330,3 @@ const data = await this.client.getObject({ | ||
private async getIncompletePartSize(id: string): Promise<number | undefined> { | ||
protected async getIncompletePartSize(id: string): Promise<number | undefined> { | ||
try { | ||
@@ -346,3 +346,3 @@ const data = await this.client.headObject({ | ||
private async deleteIncompletePart(id: string): Promise<void> { | ||
protected async deleteIncompletePart(id: string): Promise<void> { | ||
await this.client.deleteObject({ | ||
@@ -357,3 +357,3 @@ Bucket: this.bucket, | ||
*/ | ||
private async uploadParts( | ||
protected async uploadParts( | ||
metadata: MetadataValue, | ||
@@ -445,3 +445,3 @@ readStream: stream.Readable, | ||
*/ | ||
private async finishMultipartUpload(metadata: MetadataValue, parts: Array<AWS.Part>) { | ||
protected async finishMultipartUpload(metadata: MetadataValue, parts: Array<AWS.Part>) { | ||
const response = await this.client.completeMultipartUpload({ | ||
@@ -467,3 +467,3 @@ Bucket: this.bucket, | ||
*/ | ||
private async retrieveParts( | ||
protected async retrieveParts( | ||
id: string, | ||
@@ -501,3 +501,3 @@ partNumberMarker?: string | ||
*/ | ||
private async clearCache(id: string) { | ||
protected async clearCache(id: string) { | ||
log(`[${id}] removing cached data`) | ||
@@ -507,3 +507,3 @@ await this.cache.delete(id) | ||
private calcOptimalPartSize(size?: number): number { | ||
protected calcOptimalPartSize(size?: number): number { | ||
// When upload size is not know we assume largest possible value (`maxUploadSize`) | ||
@@ -796,3 +796,3 @@ if (size === undefined) { | ||
private async uniqueTmpFileName(template: string): Promise<string> { | ||
protected async uniqueTmpFileName(template: string): Promise<string> { | ||
let tries = 0 | ||
@@ -799,0 +799,0 @@ const maxTries = 10 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
87435
1475
Updated@aws-sdk/client-s3@^3.717.0
Updated@tus/utils@^0.5.1