Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-adults-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tus/s3-store": patch
---

Fix zero byte files only storing a .info file. Now correctly stores an empty file.
2 changes: 1 addition & 1 deletion packages/s3-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class S3Store extends DataStore {
'upload-id': Metadata?.['upload-id'] as string,
file: new Upload({
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),
metadata: file.metadata,
creation_date: file.creation_date,
Expand Down
36 changes: 36 additions & 0 deletions packages/s3-store/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,42 @@ describe('S3DataStore', () => {
}
})

it('should successfully upload a zero byte file', async function () {
const store = this.datastore as S3Store
const size = 0
const upload = new Upload({
id: shared.testId('zero-byte-file'),
size,
offset: 0,
})

await store.create(upload)

const offset = await store.write(
Readable.from(Buffer.alloc(size)),
upload.id,
upload.offset
)
assert.equal(offset, size, 'Write should return 0 offset')

// Check .info file via getUpload
const finalUpload = await store.getUpload(upload.id)
assert.equal(finalUpload.offset, size, '.info file should show 0 offset')

// @ts-expect-error private
const s3Client = store.client
try {
const headResult = await s3Client.getObject({
Bucket: s3ClientConfig.bucket,
Key: upload.id,
})

assert.equal(headResult.ContentLength, size, 'File should exist in S3 with 0 bytes')
} catch (error) {
assert.fail(`Zero byte file was not uploaded to S3: ${error.message}`)
}
})

shared.shouldHaveStoreMethods()
shared.shouldCreateUploads()
shared.shouldRemoveUploads() // Termination extension
Expand Down
Loading