chunked

0.0.0 • Public • Published

chunked Build Status Coverage Status Build Status

logo

HTTP Transfer-Encoding: chunked Stream for Node.js

Install

$ npm install chunked

Usage

var ChunkedStream = require('chunked');
 
process.stdin.pipe(new ChunkedStream(process.stdin)).pipe(process.stdout);

Chunked encoding

4\r\n
Wiki\r\n
5\r\n
pedia\r\n
E\r\n
 in\r\n
\r\n
chunks.\r\n
0\r\n
\r\n

==>

Wikipedia in

chunks.

More example: 分块传输编码

  • Response
HTTP/1.1 200 OK\r\n
Content-Type: text/plain\r\n
Transfer-Encoding: chunked\r\n
\r\n
25\r\n
This is the data in the first chunk\r\n\r\n
1C\r\n
and this is the second one\r\n\r\n
3\r\n
con\r\n
8\r\n
sequence\r\n
0\r\n
\r\n
  • Transfer

前两个块的数据中包含有显式的 \r\n 字符。

"This is the data in the first chunk\r\n"      (37 字符 => 十六进制: 0x25)
"and this is the second one\r\n"               (28 字符 => 十六进制: 0x1C)
"con"                                          (3  字符 => 十六进制: 0x03)
"sequence"                                     (8  字符 => 十六进制: 0x08)

应答需要以0长度的块 0\r\n\r\n 结束。

  • Decode data
This is the data in the first chunk
and this is the second one
consequence

License

(The MIT License)

Copyright (c) 2013 fengmk2 <fengmk2@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i chunked

Weekly Downloads

1

Version

0.0.0

License

MIT

Last publish

Collaborators

  • fengmk2