Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
abstract-tus-store
Advanced tools
[![Build Status](https://travis-ci.org/blockai/abstract-tus-store.svg?branch=master)](https://travis-ci.org/blockai/abstract-tus-store)
Black box test suite and interface specification for Tus-like stores. Inspired by abstract-blob-store.
Tus stores implement an API for creating and writing sequentially to "upload resources".
The required interface consists of 4 functions:
create(key[, opts])
creates a new upload resourceinfo(uploadId)
returns the current size, final key, size and metadata of an upload resourceappend(uploadId, readStream, [offset,] [opts])
to append to an upload resourcecreateReadStream(key)
creates a readable stream for the key
(primarily used to test implementation)Optional interface:
createPartial([opts])
to create a new "partial" upload resourceconcat(key, uploadIds, [opts])
concatenate "partial" upload resources to keydel(uploadId)
delete an upload resource to free up resourcesminChunkSize
optional property that announces the minimal amount of
bytes to write in an append call (except for the last one)Send a PR adding yours if you write a new one.
Include this badge in your readme if you make a new module that uses the abstract-tus-store
API:
npm install --save-dev abstract-tus-store
Requires Node v6+
See ./test directory for usage example.
In your tests:
import testStore from 'abstract-tus-store'
import memStore from 'abstract-tus-store/mem-store'
testStore({
setup() {
// Return your store instance (promise supported)
return memStore()
}
teardown() {
// you can use this hook to clean up, e.g. remove
// a temp directory
}
})
This documentation is mainly targeted at implementers.
General notes:
All functions must return promises
Error classes are available as keys on an errors
object exported by abstract-tus-store
, e.g.
import { errors } from 'abstract-tus-store'
new errors.UnknownKey('some unknown key')
Some terminology and definitions:
Create a new upload resource that will be stored at key
once
completed.
key
: String required location of the content and metadata of
the completed upload resourceopts.uploadLength
: Number expected size of the upload in bytesopts.metadata
: Object arbitrary map of key/valuesMust resolve to an object with the following properties:
uploadId
: String required unique, unpredictable identifier for
the created upload resourceIf opts.uploadLength
is not supplied, it must be passed to a
subsequent call to append
or else the upload will never complete.
Calls to create should always return a new and unique upload ID.
Get the offset
and uploadLength
of an upload resource.
uploadId
: String required a known upload IDMust resolve to an object with the following properties:
offset
: Number required offset of the upload resource. Must be
present even if the offset is 0 or the upload is already completed.uploadLength
: Number (required if known) upload length of the
upload resource.metadata
: Object metadata that was set at creation.isPartial
: Boolean true
if partial uploadMust throw an UploadNotFound
error if the upload resource does not
exist. Must not attempt to create the upload resource if it does not
already exist.
Append data to an upload resource.
uploadId
: String required a known Upload IDdata
: Readable Stream required Data that will be appended to the upload resource.offset
: Number Optional offset to help prevent data corruption.opts.beforeComplete
: Function (async) function that will be called
as beforeComplete(upload, uploadId)
before completing the upload.opts.uploadLength
: Number Used to set the length of a
deferred upload.Resolves to an object with the following properties:
offset
: Number required the new offset of the uploadupload
: Object (required if the append causes the upload to
complete) the upload object as returned by info(uploadId)
Data must be read and written to the upload resource until the data
stream ends or the upload completes (offset === uploadLength
).
The optional offset
parameter can be used to prevent data corruption.
Let's say you want to continue uploading a file. You get the current
offset of the upload with a call to info
, and then call append
with
a read stream that starts reading the file from offset
. If offset
has changed between your call to read
and append
, append
will
throw an OffsetMismatch
error.
If the call to append
causes the upload resource to complete, append
must not resolve until the upload resource's content and metadata become
available on its linked key (except for partial uploads which do not
have a key). If an object already exists at said key, it must be
overwritten.
Must throw an OffsetMismatch
error if the supplied offset is
incorrect.
Must throw an UploadNotFound
error if the upload doesn't exist.
Creates a readable stream to read the key's content from the backing store. This is mostly used for testing implementations.
key
: String required key to read from the storeonInfo
: Function optional callback that will be called with
an { contentLength, metadata }
objectTODO...
createPartial(opts)
to create a new "partial" upload resourceconcat(key, uploadIds, [opts])
concatenate "partial" upload resources to keydel(uploadId)
delete an upload resource to free up resourcesminChunkSize
optional property that announces the minimal amount of
bytes that must be written in an append call (except for the last one)FAQs
[![Build Status](https://travis-ci.org/blockai/abstract-tus-store.svg?branch=master)](https://travis-ci.org/blockai/abstract-tus-store)
The npm package abstract-tus-store receives a total of 33 weekly downloads. As such, abstract-tus-store popularity was classified as not popular.
We found that abstract-tus-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.