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

chunked-request

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chunked-request - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

## [0.4.0] - 19/05/2016
### Added
- Support responses that do not end with a trailing delimiter (#9, @MarcusLongmuir)
- Switched to `loadend` event to catch failures as well as success on XHR based transports.
## [0.3.1] - 30/03/2016

@@ -2,0 +7,0 @@ ### Added

3

lib/defaultChunkParser.js

@@ -19,2 +19,3 @@ 'use strict';

var prevChunkSuffix = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
var isFinalChunk = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];

@@ -25,3 +26,3 @@ var chunkSuffix = void 0;

if (!hasSuffix(rawChunk, entryDelimiter)) {
if (!isFinalChunk && !hasSuffix(rawChunk, entryDelimiter)) {
chunkSuffix = rawChunks.pop();

@@ -28,0 +29,0 @@ }

@@ -16,3 +16,3 @@ 'use strict';

var onRawChunk = options.onRawChunk;
var onComplete = options.onComplete;
var onRawComplete = options.onRawComplete;
var method = options.method;

@@ -27,3 +27,3 @@ var body = options.body;

if (result.done) {
return onComplete({
return onRawComplete({
statusCode: res.status,

@@ -30,0 +30,0 @@ transport: READABLE_BYTE_STREAM,

@@ -24,3 +24,3 @@ 'use strict';

function onLoadEvent() {
options.onComplete({
options.onRawComplete({
statusCode: xhr.status,

@@ -43,4 +43,4 @@ transport: MOZ_CHUNKED,

xhr.addEventListener('progress', onProgressEvent);
xhr.addEventListener('load', onLoadEvent);
xhr.addEventListener('loadend', onLoadEvent);
xhr.send(options.body);
}

@@ -20,3 +20,3 @@ 'use strict';

function onLoadEvent() {
options.onComplete({
options.onRawComplete({
statusCode: xhr.status,

@@ -39,4 +39,4 @@ transport: XHR,

xhr.addEventListener('progress', onProgressEvent);
xhr.addEventListener('load', onLoadEvent);
xhr.addEventListener('loadend', onLoadEvent);
xhr.send(options.body);
}

@@ -48,2 +48,4 @@ 'use strict';

function processRawChunk(rawChunk) {
var isFinalChunk = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
var parsedChunks = null;

@@ -54,3 +56,3 @@ var parseError = null;

try {
var _chunkParser = chunkParser(rawChunk, prevChunkSuffix);
var _chunkParser = chunkParser(rawChunk, prevChunkSuffix, isFinalChunk);

@@ -68,6 +70,16 @@ var _chunkParser2 = _slicedToArray(_chunkParser, 2);

} finally {
onChunk(parseError, parsedChunks);
if (parseError || parsedChunks !== null && parsedChunks.length > 0) {
onChunk(parseError, parsedChunks);
}
}
}
function processRawComplete(rawComplete) {
if (prevChunkSuffix != "") {
// Call the parser with isFinalChunk=true to flush the prevChunkSuffix
processRawChunk("", true);
}
onComplete(rawComplete);
}
var transport = options.transport;

@@ -84,4 +96,4 @@ if (!transport) {

credentials: credentials,
onComplete: onComplete,
onRawChunk: processRawChunk
onRawChunk: processRawChunk,
onRawComplete: processRawComplete
});

@@ -88,0 +100,0 @@ }

{
"name": "chunked-request",
"version": "0.3.1",
"version": "0.4.0",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "jsnext:main": "src/index.js",

@@ -55,3 +55,3 @@ # chunked-request

```js
(rawChunk, previousChunkSuffix) => [ parsedChunk, chunkSuffix ]
(rawChunk, previousChunkSuffix, isFinalChunk) => [ parsedChunk, chunkSuffix ]
```

@@ -65,2 +65,4 @@

`chunkParser` will be called with `isFinalChunk` as `true` when the response has completed and there was a non-empty `chunkSuffix` from the last chunk. The `rawChunk` will be an empty string and the `previousChunkSuffix` will be the last returned `chunkSuffix`.
#### onChunk (optional)

@@ -67,0 +69,0 @@ A function which implements the following interface:

@@ -11,3 +11,3 @@ const entryDelimiter = '\n';

// delimiter boundaries.
export default function defaultChunkParser(rawChunk, prevChunkSuffix = '') {
export default function defaultChunkParser(rawChunk, prevChunkSuffix = '', isFinalChunk = false) {
let chunkSuffix;

@@ -18,3 +18,3 @@

if (!hasSuffix(rawChunk, entryDelimiter)) {
if (!isFinalChunk && !hasSuffix(rawChunk, entryDelimiter)) {
chunkSuffix = rawChunks.pop();

@@ -21,0 +21,0 @@ }

@@ -7,3 +7,3 @@ import { isObject } from '../util';

const decoder = new TextDecoder();
const { onRawChunk, onComplete, method, body, credentials } = options;
const { onRawChunk, onRawComplete, method, body, credentials } = options;
const headers = marshallHeaders(options.headers);

@@ -15,3 +15,3 @@

if (result.done) {
return onComplete({
return onRawComplete({
statusCode: res.status,

@@ -18,0 +18,0 @@ transport: READABLE_BYTE_STREAM,

@@ -18,3 +18,3 @@ export const MOZ_CHUNKED = 'moz-chunked';

function onLoadEvent() {
options.onComplete({
options.onRawComplete({
statusCode: xhr.status,

@@ -37,4 +37,4 @@ transport: MOZ_CHUNKED,

xhr.addEventListener('progress', onProgressEvent);
xhr.addEventListener('load', onLoadEvent);
xhr.addEventListener('loadend', onLoadEvent);
xhr.send(options.body);
}

@@ -14,3 +14,3 @@ export const XHR = 'xhr';

function onLoadEvent() {
options.onComplete({
options.onRawComplete({
statusCode: xhr.status,

@@ -33,4 +33,4 @@ transport: XHR,

xhr.addEventListener('progress', onProgressEvent);
xhr.addEventListener('load', onLoadEvent);
xhr.addEventListener('loadend', onLoadEvent);
xhr.send(options.body);
}

@@ -25,3 +25,3 @@ import { isObject, noop } from './util';

function processRawChunk(rawChunk) {
function processRawChunk(rawChunk, isFinalChunk = false) {
let parsedChunks = null;

@@ -32,3 +32,3 @@ let parseError = null;

try {
[ parsedChunks, suffix ] = chunkParser(rawChunk, prevChunkSuffix);
[ parsedChunks, suffix ] = chunkParser(rawChunk, prevChunkSuffix, isFinalChunk);
prevChunkSuffix = suffix || "";

@@ -40,6 +40,16 @@ } catch (e) {

} finally {
onChunk(parseError, parsedChunks);
if (parseError || (parsedChunks !== null && parsedChunks.length > 0)) {
onChunk(parseError, parsedChunks);
}
}
}
function processRawComplete(rawComplete) {
if (prevChunkSuffix != "") {
// Call the parser with isFinalChunk=true to flush the prevChunkSuffix
processRawChunk("", true);
}
onComplete(rawComplete);
}
let transport = options.transport;

@@ -56,4 +66,4 @@ if (!transport) {

credentials,
onComplete,
onRawChunk: processRawChunk
onRawChunk: processRawChunk,
onRawComplete: processRawComplete
});

@@ -60,0 +70,0 @@ }

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