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

subtext

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subtext - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

API.md

2

lib/index.js
// Load modules
var Crypto = require('crypto');
var Fs = require('fs');
var Os = require('os');
var Path = require('path');
var Stream = require('stream');

@@ -8,0 +6,0 @@ var Zlib = require('zlib');

{
"name": "subtext",
"description": "HTTP payload parsing",
"version": "2.0.0",
"version": "2.0.1",
"repository": "git://github.com/hapijs/subtext",

@@ -28,3 +28,3 @@ "main": "lib/index.js",

"form-data": "0.1.x",
"lab": "5.x.x"
"lab": "6.x.x"
},

@@ -31,0 +31,0 @@ "scripts": {

#subtext
HTTP payload parsing.
HTTP payload parser.
[![Build Status](https://secure.travis-ci.org/hapijs/subtext.png)](http://travis-ci.org/hapijs/subtext)
Lead Maintainer - [Eran Hammer](https://github.com/hueniverse)
Lead Maintainer - [John Brett](https://github.com/johnbrett)
subtext parses the request body and exposes it in a callback.
## Example
```javascript
var Http = require('http');
var Subtext = require('subtext');
Http.createServer(function (request, response) {
Subtext.parse(request, null, { parse: true, output: 'data' }, function (err, parsed) {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('Payload contains: ' + parsed.payload.toString());
});
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
```
## API
See the [API Reference](API.md)

@@ -11,3 +11,2 @@ // Load modules

var FormData = require('form-data');
var Hoek = require('hoek');
var Lab = require('lab');

@@ -1122,2 +1121,91 @@ var Subtext = require('..');

it('parses multiple files of different sizes', function (done) {
var path = Path.join(__dirname, './file/smallimage.png');
var path2 = Path.join(__dirname, './file/image.jpg');
var stats = Fs.statSync(path);
var stats2 = Fs.statSync(path2);
var form = new FormData();
form.append('file1', Fs.createReadStream(path));
form.append('file2', Fs.createReadStream(path2));
form.headers = form.getHeaders();
Subtext.parse(form, null, { parse: true, output: 'file' }, function (err, parsed) {
expect(err).to.not.exist();
expect(parsed.payload.file1.bytes).to.equal(stats.size);
expect(parsed.payload.file2.bytes).to.equal(stats2.size);
Fs.unlinkSync(parsed.payload.file1.path);
Fs.unlinkSync(parsed.payload.file2.path);
done();
});
});
it('parses multiple files of different sizes', function (done) {
var path = Path.join(__dirname, './file/image.jpg');
var path2 = Path.join(__dirname, './file/smallimage.png');
var stats = Fs.statSync(path);
var stats2 = Fs.statSync(path2);
var form = new FormData();
form.append('file1', Fs.createReadStream(path));
form.append('file2', Fs.createReadStream(path2));
form.headers = form.getHeaders();
Subtext.parse(form, null, { parse: true, output: 'file' }, function (err, parsed) {
expect(err).to.not.exist();
expect(parsed.payload.file1.bytes).to.equal(stats.size);
expect(parsed.payload.file2.bytes).to.equal(stats2.size);
Fs.unlinkSync(parsed.payload.file1.path);
Fs.unlinkSync(parsed.payload.file2.path);
done();
});
});
it('parses multiple small files', function (done) {
var path = Path.join(__dirname, './file/smallimage.png');
var stats = Fs.statSync(path);
var form = new FormData();
form.append('file1', Fs.createReadStream(path));
form.append('file2', Fs.createReadStream(path));
form.headers = form.getHeaders();
Subtext.parse(form, null, { parse: true, output: 'file' }, function (err, parsed) {
expect(err).to.not.exist();
expect(parsed.payload.file1.bytes).to.equal(stats.size);
expect(parsed.payload.file2.bytes).to.equal(stats.size);
Fs.unlinkSync(parsed.payload.file1.path);
done();
});
});
it('parses multiple larger files', function (done) {
var path = Path.join(__dirname, './file/image.jpg');
var stats = Fs.statSync(path);
var form = new FormData();
form.append('file1', Fs.createReadStream(path));
form.append('file2', Fs.createReadStream(path));
form.headers = form.getHeaders();
Subtext.parse(form, null, { parse: true, output: 'file' }, function (err, parsed) {
expect(err).to.not.exist();
expect(parsed.payload.file1.bytes).to.equal(stats.size);
expect(parsed.payload.file2.bytes).to.equal(stats.size);
Fs.unlinkSync(parsed.payload.file1.path);
Fs.unlinkSync(parsed.payload.file2.path);
done();
});
});
it('parses multiple files while waiting for last file to be written', { parallel: false }, function (done) {

@@ -1172,3 +1260,2 @@

expect(err).to.not.exist();
var fileContents = Fs.readFileSync(path);
expect(parsed.payload.my_file.name).to.equal('subtext');

@@ -1237,3 +1324,2 @@ done();

var path = Path.join(__dirname, './file/image.jpg');
var stats = Fs.statSync(path);
var fileStream = Fs.createReadStream(path);

@@ -1240,0 +1326,0 @@ var fileContents = Fs.readFileSync(path);

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