Giter Site home page Giter Site logo

chunked.js's Introduction

chunked.js

Polyfill for chunked XMLHttpRequest extension proposed by Mozilla.

Was started as polyfill for Streams API, but due to the sheer size of the spec, it was reduced to handle just downloading, which is exactly, what Mozilla's extension does.

###Scenario: The main usage for this should be with downloading large files via http. It aims to fix problems like:

  • Large files need a long time to download. Currently processing them is only possible after loading has finished. With chunked.js you can start processing as soon as the first chunk (scnr) was received.
  • Large files may result in an Javascript heap overflow. Via chunked.js you can choose to only process a smaller fraction at a time.

###Usage:

XMLHttpRequest.responseType = < normal types > | "chunked-text" | "chunked-blob" | "chunked-arraybuffer";

Setting one of the chunked response types, results in XMLHttpRequest.response being only available/set in progress events (in contrast to load event). XMLHttpRequest.response then contains the data received since the last progress event.

###Example: <script src="chunked.min.js"></script>

var req = new XMLHttpRequest();
req.open( "GET", "http://ipv4.download.thinkbroadband.com/512MB.zip" );
req.responseType = "chunked-array" // alternate `chunked-text` and `chunked-blob`
req.onload = function( event ) {
};
req.onprogress = function( event ) {
    // Access chunk, between last progress call and now
    var chunk = req.result;
    my_incredible_function( chunk );
};
req.send();

###Internas: Wrapper is not derived (prototype = new XMLHttpRequest()) from XMLHttpRequest, since Javascript forbids this for DOMElements. It wraps XMLHttpRequest as well as possible. Be aware that naive prototype-checking may fail, though! Does not yet work for ftp!

chunked.js's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.