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

tus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tus - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

18

lib/tus.js

@@ -56,3 +56,3 @@ var fs = require('fs'),

writeFile(directory + "/" + name + ".bin", new Buffer(0)),
writeFile(directory + "/" + name + ".info", JSON.stringify({entityLength: entityLength, offset: 0, meta: meta}), "utf8"),
writeFile(directory + "/" + name + ".info", JSON.stringify({name: name, entityLength: entityLength, offset: 0, meta: meta}), "utf8"),
function() {

@@ -78,2 +78,6 @@ return name;

if (options.maxFileSize != null && isNaN(options.maxFileSize)) {
throw new Error("maxFileSize option must be a number");
}
function getInfo(id) {

@@ -85,3 +89,7 @@ return readFile(options.directory + "/" + id + ".info").then(JSON.parse);

getPositiveIntHeader(req, "Entity-Length").then(function(entityLength) {
return createEmptyFile(crypto.randomBytes(16).toString('hex'), options.directory, entityLength, {});
if (options.maxFileSize != null && entityLength > options.maxFileSize) {
throw new BadRequest("File exceeds maximum allowed file size of " + options.maxFileSize + " bytes");
}
return createEmptyFile(crypto.randomBytes(16).toString('hex'), options.directory, entityLength, {contentType: req.get('Content-Type') || null, filename: req.get('Entity-Name') || null});
}).then(function(name) {

@@ -145,3 +153,7 @@ res.set('Location', url.resolve(req.protocol + '://' + req.get('host') + req.originalUrl + "/", name));

info.offset = byteOffset;
return writeFile(options.directory + "/" + id + ".info", JSON.stringify(info), "utf8");
var promise = writeFile(options.directory + "/" + id + ".info", JSON.stringify(info), "utf8");
if (typeof options.complete === "function") {
options.complete(info);
}
return promise;
}

@@ -148,0 +160,0 @@ return Promise.resolve();

2

package.json
{
"name": "tus",
"version": "0.1.0",
"version": "0.1.1",
"description": "Node.js resumable upload middleware for express/connect",

@@ -5,0 +5,0 @@ "main": "lib/tus.js",

@@ -13,2 +13,30 @@ # node-tus

## Usage
To attach the resumable upload middleware to express or connect, create an upload server by calling `createServer` passing it an `options` object. Available options are:
- **directory** - String - Path where to upload the files (required)
- **maxFileSize** - Number - Maximum file size for uploads, in bytes (optional)
- **complete** - Function - Callback to inform when a file (all chunks) have been uploaded. Passes the file metadata as an argument (optional)
Example:
```js
var express = require("express"),
upload = require("tus");
var app = express();
var port = 3000;
app.use("/files", upload.createServer({
directory: __dirname + "/uploads",
maxFileSize: 1024,
complete: function(fileMetadata) {
console.log("File uploaded with the following metadata:", fileMetadata);
}
}));
app.listen(port);
```
## Running Tests

@@ -15,0 +43,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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