GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - jchristn/ChunkDecoder: Library for decoding chunk-transfer-encoded data, particularly from HTTP.

BranchesTags
Open more actions menu

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
ChunkDecoder
ChunkDecoder
 
 
Test
Test
 
 
assets
assets
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
ChunkDecoder.sln
ChunkDecoder.sln
 
 
DONATIONS.md
DONATIONS.md
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 

Repository files navigation

alt tag

ChunkDecoder

NuGet Version NuGet

ChunkDecoder is useful to help decode chunk-transfer-encoded data, particularly from HTTP.

New in v1.0.4

  • XML documentation

Usage

using ChunkDecoder;

public Decoder decoder = new Decoder();

// process a byte array
if (decoder.Decode(data, out outData))
{
  // success
}

// process a stream
long outLength = 0;
MemoryStream outStream = null;
if (decoder.Decode(stream, out outLength, out outStream))
{
  // success
}

Functionality

Chunk-transfer-encoded data is sent in segments, where each segment is comprised of a line containing the length (in hexadecimal) and the subsequent line containing the payload. Each line ends with a carriage return and line feed .

The final line ends with 0<crlf><crlf> indicating the end of the stream.

For instance:

6<crlf>        // 6 bytes of data will follow.
Hello_<crlf>   // data.  The value is 'Hello_' where _ is actually a space.
5<crlf>        // 5 bytes of data will follow.
World<crlf>    // data.  The value is 'World'.
0<crlf><crlf>  // end of stream.

Results in:

Hello world

For more information, please see:

  • https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding
  • https://en.wikipedia.org/wiki/Chunked_transfer_encoding

Callbacks

In cases where the supplied data has signatures, i.e.

6;chunk-signature=foo<crlf>  // 6 bytes of data will follow, and the signature of the chunk is foo.
Hello_<crlf>                 // data.  The value is 'Hello ' and _ is actually a space.
5;chunk-signature:bar<crlf>  // 5 bytes of data will follow, and the signature of the chunk is bar.
World<crlf>                  // data.  The value is 'World'.
0;<crlf><crlf>               // end of stream.

You can assigned the Decoder.ProcessSignature callback, which has the following signature:

using System.Collections.Generic;

static bool ProcessSignature(KeyValuePair<string, string>, byte[] data)
{
	return true;
}

This method should return true, otherwise ChunkDecoder will assume there is an error and terminate.

If you wish to process each chunk as it is read, set the Decoder.ProcessChunk callback, which has the followning signature:

static bool ProcessChunk(byte[] data)
{
	return true;
}

This method should also return true, for the same reason. ProcessChunk is always called after ProcessSignature.

Version History

Refer to CHANGELOG.md

About

Library for decoding chunk-transfer-encoded data, particularly from HTTP.

Topics

chunkchunk-datadecoderhttphttp-serverhttpshttps-servernugetserverweb

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity

Stars

2 stars

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.