Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tus/file-store

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tus/file-store - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

18

dist/configstores/FileConfigstore.d.ts

@@ -1,3 +0,3 @@

import { Upload } from '@tus/server';
import { Configstore } from './Types';
import {Upload} from '@tus/server'
import {Configstore} from './Types'
/**

@@ -8,9 +8,9 @@ * FileConfigstore writes the `Upload` JSON metadata to disk next the uploaded file itself.

export declare class FileConfigstore implements Configstore {
directory: string;
constructor(path: string);
get(key: string): Promise<Upload | undefined>;
set(key: string, value: Upload): Promise<void>;
delete(key: string): Promise<void>;
list(): Promise<Array<string>>;
private resolve;
directory: string
constructor(path: string)
get(key: string): Promise<Upload | undefined>
set(key: string, value: Upload): Promise<void>
delete(key: string): Promise<void>
list(): Promise<Array<string>>
private resolve
}

@@ -1,9 +0,11 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileConfigstore = void 0;
const promises_1 = __importDefault(require("node:fs/promises"));
const node_path_1 = __importDefault(require("node:path"));
'use strict'
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : {default: mod}
}
Object.defineProperty(exports, '__esModule', {value: true})
exports.FileConfigstore = void 0
const promises_1 = __importDefault(require('node:fs/promises'))
const node_path_1 = __importDefault(require('node:path'))
/**

@@ -14,31 +16,32 @@ * FileConfigstore writes the `Upload` JSON metadata to disk next the uploaded file itself.

class FileConfigstore {
constructor(path) {
this.directory = path;
constructor(path) {
this.directory = path
}
async get(key) {
try {
const buffer = await promises_1.default.readFile(this.resolve(key), 'utf8')
return JSON.parse(buffer)
} catch {
return undefined
}
async get(key) {
try {
const buffer = await promises_1.default.readFile(this.resolve(key), 'utf8');
return JSON.parse(buffer);
}
catch {
return undefined;
}
}
async set(key, value) {
await promises_1.default.writeFile(this.resolve(key), JSON.stringify(value));
}
async delete(key) {
await promises_1.default.rm(this.resolve(key));
}
async list() {
const files = await promises_1.default.readdir(this.directory);
const sorted = files.sort((a, b) => a.localeCompare(b));
const name = (file) => node_path_1.default.basename(file, '.json');
// To only return tus file IDs we check if the file has a corresponding JSON info file
return sorted.filter((file, idx) => idx < sorted.length - 1 && name(file) === name(sorted[idx + 1]));
}
resolve(key) {
return node_path_1.default.resolve(this.directory, `${key}.json`);
}
}
async set(key, value) {
await promises_1.default.writeFile(this.resolve(key), JSON.stringify(value))
}
async delete(key) {
await promises_1.default.rm(this.resolve(key))
}
async list() {
const files = await promises_1.default.readdir(this.directory)
const sorted = files.sort((a, b) => a.localeCompare(b))
const name = (file) => node_path_1.default.basename(file, '.json')
// To only return tus file IDs we check if the file has a corresponding JSON info file
return sorted.filter(
(file, idx) => idx < sorted.length - 1 && name(file) === name(sorted[idx + 1])
)
}
resolve(key) {
return node_path_1.default.resolve(this.directory, `${key}.json`)
}
}
exports.FileConfigstore = FileConfigstore;
exports.FileConfigstore = FileConfigstore

@@ -1,3 +0,3 @@

import { Upload } from '@tus/server';
import { Configstore } from './Types';
import {Upload} from '@tus/server'
import {Configstore} from './Types'
/**

@@ -10,9 +10,9 @@ * Memory based configstore.

export declare class MemoryConfigstore implements Configstore {
data: Map<string, string>;
get(key: string): Promise<Upload | undefined>;
set(key: string, value: Upload): Promise<void>;
delete(key: string): Promise<void>;
list(): Promise<Array<string>>;
private serializeValue;
private deserializeValue;
data: Map<string, string>
get(key: string): Promise<Upload | undefined>
set(key: string, value: Upload): Promise<void>
delete(key: string): Promise<void>
list(): Promise<Array<string>>
private serializeValue
private deserializeValue
}

@@ -1,5 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemoryConfigstore = void 0;
const server_1 = require("@tus/server");
'use strict'
Object.defineProperty(exports, '__esModule', {value: true})
exports.MemoryConfigstore = void 0
const server_1 = require('@tus/server')
/**

@@ -12,24 +12,24 @@ * Memory based configstore.

class MemoryConfigstore {
constructor() {
this.data = new Map();
}
async get(key) {
return this.deserializeValue(this.data.get(key));
}
async set(key, value) {
this.data.set(key, this.serializeValue(value));
}
async delete(key) {
this.data.delete(key);
}
async list() {
return [...this.data.keys()];
}
serializeValue(value) {
return JSON.stringify(value);
}
deserializeValue(buffer) {
return buffer ? new server_1.Upload(JSON.parse(buffer)) : undefined;
}
constructor() {
this.data = new Map()
}
async get(key) {
return this.deserializeValue(this.data.get(key))
}
async set(key, value) {
this.data.set(key, this.serializeValue(value))
}
async delete(key) {
this.data.delete(key)
}
async list() {
return [...this.data.keys()]
}
serializeValue(value) {
return JSON.stringify(value)
}
deserializeValue(buffer) {
return buffer ? new server_1.Upload(JSON.parse(buffer)) : undefined
}
}
exports.MemoryConfigstore = MemoryConfigstore;
exports.MemoryConfigstore = MemoryConfigstore

@@ -1,4 +0,4 @@

import { RedisClientType } from '@redis/client';
import { Upload } from '@tus/server';
import { Configstore } from './Types';
import {RedisClientType} from '@redis/client'
import {Upload} from '@tus/server'
import {Configstore} from './Types'
/**

@@ -10,11 +10,11 @@ * Redis based configstore.

export declare class RedisConfigstore implements Configstore {
private redis;
private prefix;
constructor(redis: RedisClientType, prefix?: string);
get(key: string): Promise<Upload | undefined>;
set(key: string, value: Upload): Promise<void>;
delete(key: string): Promise<void>;
list(): Promise<Array<string>>;
private serializeValue;
private deserializeValue;
private redis
private prefix
constructor(redis: RedisClientType, prefix?: string)
get(key: string): Promise<Upload | undefined>
set(key: string, value: Upload): Promise<void>
delete(key: string): Promise<void>
list(): Promise<Array<string>>
private serializeValue
private deserializeValue
}

@@ -1,4 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisConfigstore = void 0;
'use strict'
Object.defineProperty(exports, '__esModule', {value: true})
exports.RedisConfigstore = void 0
/**

@@ -10,27 +10,27 @@ * Redis based configstore.

class RedisConfigstore {
constructor(redis, prefix = '') {
this.redis = redis;
this.prefix = prefix;
this.redis = redis;
this.prefix = prefix;
}
async get(key) {
return this.deserializeValue(await this.redis.get(this.prefix + key));
}
async set(key, value) {
await this.redis.set(this.prefix + key, this.serializeValue(value));
}
async delete(key) {
await this.redis.del(this.prefix + key);
}
async list() {
return this.redis.keys(this.prefix + '*');
}
serializeValue(value) {
return JSON.stringify(value);
}
deserializeValue(buffer) {
return buffer ? JSON.parse(buffer) : undefined;
}
constructor(redis, prefix = '') {
this.redis = redis
this.prefix = prefix
this.redis = redis
this.prefix = prefix
}
async get(key) {
return this.deserializeValue(await this.redis.get(this.prefix + key))
}
async set(key, value) {
await this.redis.set(this.prefix + key, this.serializeValue(value))
}
async delete(key) {
await this.redis.del(this.prefix + key)
}
async list() {
return this.redis.keys(this.prefix + '*')
}
serializeValue(value) {
return JSON.stringify(value)
}
deserializeValue(buffer) {
return buffer ? JSON.parse(buffer) : undefined
}
}
exports.RedisConfigstore = RedisConfigstore;
exports.RedisConfigstore = RedisConfigstore

@@ -1,7 +0,7 @@

import { Upload } from '@tus/server';
import {Upload} from '@tus/server'
export interface Configstore {
get(key: string): Promise<Upload | undefined>;
set(key: string, value: Upload): Promise<void>;
delete(key: string): Promise<void>;
list?(): Promise<Array<string>>;
get(key: string): Promise<Upload | undefined>
set(key: string, value: Upload): Promise<void>
delete(key: string): Promise<void>
list?(): Promise<Array<string>>
}

@@ -1,2 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
'use strict'
Object.defineProperty(exports, '__esModule', {value: true})
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@tus/file-store",
"version": "1.0.0-beta.1",
"description": "Local file storage for @tus/server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/tus/tus-node-server#readme",
"bugs": "https://github.com/tus/tus-node-server/issues",
"repository": "tus/tus-node-server",
"files": [
"README.md",
"LICENSE",
"dist"
],
"license": "MIT",
"scripts": {
"build": "tsc",
"lint": "eslint .",
"format": "eslint --fix .",
"test": "mocha test.ts --exit --extension ts --require ts-node/register"
},
"dependencies": {
"configstore": "^5.0.1",
"debug": "^4.3.3"
},
"devDependencies": {
"@tus/server": "workspace:^",
"@types/configstore": "^6.0.0",
"@types/debug": "^4.1.7",
"@types/mocha": "^10.0.1",
"@types/node": "latest",
"eslint": "^8.29.0",
"eslint-config-custom": "workspace:*",
"mocha": "^10.1.0",
"should": "^13.2.3",
"typescript": "latest"
},
"peerDependencies": {
"@tus/server": "workspace:^"
},
"engines": {
"node": ">=16"
}
"$schema": "https://json.schemastore.org/package.json",
"name": "@tus/file-store",
"version": "1.0.0-beta.1",
"description": "Local file storage for @tus/server",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/tus/tus-node-server#readme",
"bugs": "https://github.com/tus/tus-node-server/issues",
"repository": "tus/tus-node-server",
"files": [
"README.md",
"LICENSE",
"dist"
],
"license": "MIT",
"scripts": {
"build": "tsc",
"lint": "eslint .",
"format": "eslint --fix .",
"test": "mocha test.ts --exit --extension ts --require ts-node/register"
},
"dependencies": {
"configstore": "^5.0.1",
"debug": "^4.3.3"
},
"devDependencies": {
"@tus/server": "workspace:^",
"@types/configstore": "^6.0.0",
"@types/debug": "^4.1.7",
"@types/mocha": "^10.0.1",
"@types/node": "latest",
"eslint": "^8.29.0",
"eslint-config-custom": "workspace:*",
"mocha": "^10.1.0",
"should": "^13.2.3",
"typescript": "latest"
},
"peerDependencies": {
"@tus/server": "workspace:^"
},
"engines": {
"node": ">=16"
}
}
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@tus/file-store",
"version": "1.3.1",
"version": "1.3.2",
"description": "Local file storage for @tus/server",

@@ -31,5 +31,5 @@ "main": "dist/index.js",

"@types/node": "^20.11.5",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-custom": "^0.0.0",
"mocha": "^10.2.0",
"mocha": "^10.4.0",
"should": "^13.2.3",

@@ -36,0 +36,0 @@ "typescript": "^5.3.3"

# `@tus/file-store`
> 👉 **Note**: since 1.0.0 packages are split and published under the `@tus` scope.
> The old package, `tus-node-server`, is considered unstable and will only receive security fixes.
> Make sure to use the new packages.
> 👉 **Note**: since 1.0.0 packages are split and published under the `@tus` scope. The
> old package, `tus-node-server`, is considered unstable and will only receive security
> fixes. Make sure to use the new packages.

@@ -58,4 +58,4 @@ ## Contents

Default uses `FileKvStore` which puts the metadata file next to the uploaded file.
See the exported [KV stores][kvstores] from `@tus/server` for more information.
Default uses `FileKvStore` which puts the metadata file next to the uploaded file. See the
exported [KV stores][kvstores] from `@tus/server` for more information.

@@ -66,8 +66,9 @@ #### `options.expirationPeriodInMilliseconds`

This is since the time of creation, not modification. Once an upload is considered expired,
uploads can be removed with [`cleanUpExpiredUploads`][].
This is since the time of creation, not modification. Once an upload is considered
expired, uploads can be removed with [`cleanUpExpiredUploads`][].
## Extensions
The tus protocol supports optional [extensions][]. Below is a table of the supported extensions in `@tus/file-store`.
The tus protocol supports optional [extensions][]. Below is a table of the supported
extensions in `@tus/file-store`.

@@ -87,4 +88,4 @@ | Extension | `@tus/file-store` |

For demonstration purposes we will create a memory config store, but that's not a good idea.
It's written in TypeScript.
For demonstration purposes we will create a memory config store, but that's not a good
idea. It's written in TypeScript.

@@ -133,11 +134,14 @@ ```ts

See [`contributing.md`](https://github.com/tus/tus-node-server/blob/main/.github/contributing.md).
See
[`contributing.md`](https://github.com/tus/tus-node-server/blob/main/.github/contributing.md).
## License
[MIT](https://github.com/tus/tus-node-server/blob/master/license) © [tus](https://github.com/tus)
[MIT](https://github.com/tus/tus-node-server/blob/master/license) ©
[tus](https://github.com/tus)
[extensions]: https://tus.io/protocols/resumable-upload.html#protocol-extensions
[creation]: https://tus.io/protocols/resumable-upload.html#creation
[creation with upload]: https://tus.io/protocols/resumable-upload.html#creation-with-upload
[creation with upload]:
https://tus.io/protocols/resumable-upload.html#creation-with-upload
[expiration]: https://tus.io/protocols/resumable-upload.html#expiration

@@ -147,4 +151,6 @@ [checksum]: https://tus.io/protocols/resumable-upload.html#checksum

[concatenation]: https://tus.io/protocols/resumable-upload.html#concatenation
[`cleanUpExpiredUploads`]: https://github.com/tus/tus-node-server/tree/main/packages/server#cleanupexpireduploads
[`cleanUpExpiredUploads`]:
https://github.com/tus/tus-node-server/tree/main/packages/server#cleanupexpireduploads
[kvstores]: https://github.com/tus/tus-node-server/tree/main/packages/server#kvstores
[`KvStore`]: https://github.com/tus/tus-node-server/blob/main/packages/server/src/kvstores/Types.ts
[`KvStore`]:
https://github.com/tus/tus-node-server/blob/main/packages/utils/src/kvstores/Types.ts
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc