<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.7.3">Jekyll</generator><link href="https://suvanika.github.io/https://suvanika.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://suvanika.github.io/https://suvanika.github.io/" rel="alternate" type="text/html" /><updated>2018-06-28T11:38:52+00:00</updated><id>https://suvanika.github.io/https://suvanika.github.io/</id><title type="html">Suvanika Senthil</title><subtitle>Amateur Coder.</subtitle><entry><title type="html">Javascript in Angular</title><link href="https://suvanika.github.io/https://suvanika.github.io/Javascript/" rel="alternate" type="text/html" title="Javascript in Angular" /><published>2018-06-06T00:00:00+00:00</published><updated>2018-06-06T00:00:00+00:00</updated><id>https://suvanika.github.io/https://suvanika.github.io/Javascript</id><content type="html" xml:base="https://suvanika.github.io/https://suvanika.github.io/Javascript/">&lt;blockquote&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;I recently stumbled across whammy.js , a tool that converts images to video on the client side (I know, you’re going whaaaaaaat). It requires images of the webp format, a format brought around by google and which is supported only in chromium based browsers. It doesn’t really seem like firefox would be supporting that in the near future. These images are substantially smaller than their png or jpeg counterparts. whammy.js converts these itsy-bitsy images into webm format video, (mostly supported by browsers). It also makes it easier to embed the video in your html document.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;&lt;em&gt;I knew I needed this. It was perfect, client side image to video conversion, that’s a developer’s and a user’s dream. Server-hassle free. Instant conversion, reduced size without the loss of resolution or pixels.&lt;/em&gt;&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;However I was riddled with the problem of using the javascript file in angular. :(&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;After about half a day of googling up articles on the internet, I was convinced that I would either have to include a typings.d.ts file (which does not exist) for the javascript file, or completely rewrite it in typescript. I was pretty beaten up and frustrated, I mean, typescript is a superset of javascript , it’s going to end up being javascript at some point of time.O.o&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Turns out, it isn’t that hard. You just have to be an expert at googling stuff and putting together pieces and it didn’t take me more than ten minutes to put it all together and get it working. Although the code was riddled with bugs, so i spent more than an entire day, figuring out how it worked and tracing where the execution with horrendously wrong, but in the end I had a working script, I’ve given users (chrome and opera users only, sorry :( ..) the power to download &amp;gt;5o mb worth of images as a super compressed video in milliseconds (I do give whammy most of the credit though, can’t deny that).&lt;/p&gt;

&lt;h2 class=&quot;graf graf--h3&quot;&gt;&lt;em class=&quot;markup--em markup--h3-em&quot;&gt;So how did I do it&lt;/em&gt;&lt;/h2&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Easy-peasy.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Add your javascript file to the assets folder.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Open up your angular-cli.json, and under scripts, add the location of your javascript file:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*GzwzuEjuSuiw6fDdPzKPTA.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;And now all you have to do is hop over to your component, or your service or wherever it is that you want to use the file , and declare the function explicitly over there:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*0NO_sgZ8e4xQKfnysuYOvg.png&quot; /&gt;&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;and now you are good to start using.&lt;/p&gt;

&lt;figure class=&quot;graf graf--figure&quot;&gt;&lt;img class=&quot;graf-image&quot; src=&quot;https://cdn-images-1.medium.com/max/800/1*aOWK64k9DsvPxrf6jgS_Lw.png&quot; data-image-id=&quot;1*aOWK64k9DsvPxrf6jgS_Lw.png&quot; data-width=&quot;441&quot; data-height=&quot;56&quot; /&gt;&lt;/figure&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;That is how it’s done.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Do check out whammy.js, or ccapture(built on whammy.js) they are pretty awesome, if you wanna do image to video conversion on the client side. :)&lt;/p&gt;</content><author><name></name></author><summary type="html">I recently stumbled across whammy.js , a tool that converts images to video on the client side (I know, you’re going whaaaaaaat). It requires images of the webp format, a format brought around by google and which is supported only in chromium based browsers. It doesn’t really seem like firefox would be supporting that in the near future. These images are substantially smaller than their png or jpeg counterparts. whammy.js converts these itsy-bitsy images into webm format video, (mostly supported by browsers). It also makes it easier to embed the video in your html document. I knew I needed this. It was perfect, client side image to video conversion, that’s a developer’s and a user’s dream. Server-hassle free. Instant conversion, reduced size without the loss of resolution or pixels. However I was riddled with the problem of using the javascript file in angular. :( After about half a day of googling up articles on the internet, I was convinced that I would either have to include a typings.d.ts file (which does not exist) for the javascript file, or completely rewrite it in typescript. I was pretty beaten up and frustrated, I mean, typescript is a superset of javascript , it’s going to end up being javascript at some point of time.O.o Turns out, it isn’t that hard. You just have to be an expert at googling stuff and putting together pieces and it didn’t take me more than ten minutes to put it all together and get it working. Although the code was riddled with bugs, so i spent more than an entire day, figuring out how it worked and tracing where the execution with horrendously wrong, but in the end I had a working script, I’ve given users (chrome and opera users only, sorry :( ..) the power to download &amp;gt;5o mb worth of images as a super compressed video in milliseconds (I do give whammy most of the credit though, can’t deny that).</summary></entry><entry><title type="html">Multipart download in Angular</title><link href="https://suvanika.github.io/https://suvanika.github.io/Js-inAG5/" rel="alternate" type="text/html" title="Multipart download in Angular" /><published>2018-05-21T00:00:00+00:00</published><updated>2018-05-21T00:00:00+00:00</updated><id>https://suvanika.github.io/https://suvanika.github.io/Js-inAG5</id><content type="html" xml:base="https://suvanika.github.io/https://suvanika.github.io/Js-inAG5/">&lt;p class=&quot;graf graf--p&quot;&gt; We’ll be looking at how to write a client side multipart download code in angular 5. If you do not know what multipart download is , please do checkout my previous write up &lt;a class=&quot;markup--anchor markup--p-anchor&quot; href=&quot;https://medium.com/@suvanika/multipart-download-and-byte-ranges-b5d6b7577e95&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;multipart-download&lt;/a&gt;.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;This comes in handy if you are scripting a client side web application that needs to download a couple of objects that a pretty big in size. In my case, they were images of the range 5–15 mb. Which is pretty huge. It also helps you use your entire allocated bandwidth (uses all the allocated browser threads).&lt;/p&gt;

&lt;h3 class=&quot;graf graf--h3&quot;&gt;Writing a Service&lt;/h3&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Create a service , say file-download.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;&lt;strong class=&quot;markup--strong markup--p-strong&quot;&gt;&lt;em class=&quot;markup--em markup--p-em&quot;&gt;ng generate service file-download&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;It gets auto imported to your app.module.ts, but do make sure, and also include in the providers array.&lt;/p&gt;

&lt;blockquote class=&quot;graf graf--blockquote&quot;&gt;import {MultipartService} from ‘./download-file.service’;&lt;/blockquote&gt;
&lt;blockquote class=&quot;graf graf--blockquote&quot;&gt;@NgModule({&lt;/blockquote&gt;
&lt;blockquote class=&quot;graf graf--blockquote&quot;&gt;providers: [MultipartService]&lt;/blockquote&gt;
&lt;blockquote class=&quot;graf graf--blockquote&quot;&gt;bootstrap: [AppComponent]&lt;/blockquote&gt;
&lt;blockquote class=&quot;graf graf--blockquote&quot;&gt;})&lt;/blockquote&gt;
&lt;blockquote class=&quot;graf graf--blockquote&quot;&gt;export class AppModule { }&lt;/blockquote&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Now switch over to our service.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Time to write our method.&lt;/p&gt;

&lt;figure class=&quot;graf graf--figure&quot;&gt;&lt;img class=&quot;graf-image&quot; src=&quot;https://gettingstartedfornoobs.files.wordpress.com/2018/06/8d72e-1kuzllufj0zqg_8yycztxww.png&quot; /&gt;&lt;/figure&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;First we are declaring variables fileSize and assigning it the value of the file we want to download. Don’t forget to initialize a variable url and pass the url in it.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;We figure out the chunksize (bytes) by dividing the fileSize by the number of parallel download requests we need, in this case 5.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;We iterate over the number of chunks and store the corresponding start and end values of each chunk in json object ‘chunks’.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;Now we have to a set a HTTP header ‘range’ and pass in the byte ranges. So we append ‘&lt;em class=&quot;markup--em markup--p-em&quot;&gt;Range, rangeval&lt;/em&gt;’ , where rangeval is a string that contains bytes=&lt;strong class=&quot;markup--strong markup--p-strong&quot;&gt;&lt;em class=&quot;markup--em markup--p-em&quot;&gt;start&lt;/em&gt;&lt;/strong&gt;-&lt;strong class=&quot;markup--strong markup--p-strong&quot;&gt;&lt;em class=&quot;markup--em markup--p-em&quot;&gt;end, where start and end are numbers taken from the json object.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;We are using the httpClientModule to take care of our http communication. So dont forget to import that in your service and in your module.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;we append the url and set &lt;em class=&quot;markup--em markup--p-em&quot;&gt;httpheaders in the headers parameter of http get and push into an array &lt;/em&gt;&lt;strong class=&quot;markup--strong markup--p-strong&quot;&gt;&lt;em class=&quot;markup--em markup--p-em&quot;&gt;headers&lt;/em&gt;&lt;/strong&gt;&lt;em class=&quot;markup--em markup--p-em&quot;&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h3 class=&quot;graf graf--h3&quot;&gt;Firing the Requests&lt;/h3&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;import { forkJoin } from ‘rxjs/observable/forkJoin’;&lt;/p&gt;

&lt;figure class=&quot;graf graf--figure&quot;&gt;&lt;img class=&quot;graf-image&quot; src=&quot;https://gettingstartedfornoobs.files.wordpress.com/2018/06/4ecaf-1_yh-gmqihvhk8trj3mfj0g.png&quot; /&gt;&lt;/figure&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;forkjoin is an operator from the rxjs library. It helps execute observables at once and emit their final values.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;We are using it here to fire our http requests, that downloads our file chunk by chunk. Forkjoin, pieces back the chunks (or blobs) and emits one final blob.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;We subscribe to it to acquire the final blob. We are using a module file-saver&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;import { saveAs } from ‘file-saver/FileSaver’;&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;to save our blob to our file system in the desired format.&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;We’re invoking a method saveToFileSystem that does this for us. We pass in the entire blob as a parameter.&lt;/p&gt;

&lt;figure class=&quot;graf graf--figure&quot;&gt;&lt;img class=&quot;graf-image&quot; src=&quot;https://gettingstartedfornoobs.files.wordpress.com/2018/06/08205-1tmnsd4komnlcem6zulikrw.png&quot; /&gt;&lt;/figure&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;The header content-disposition would be available to you only if the CORS allow header : content-disposition is set on the server side. You might be able to view it in your browser, but if the header is not set, the browser does not let your application access it. (I know, CORS is a pain in the b.)&lt;/p&gt;
&lt;p class=&quot;graf graf--p&quot;&gt;So that’s it. It’s a wrap guys.&lt;/p&gt;</content><author><name></name></author><summary type="html">We’ll be looking at how to write a client side multipart download code in angular 5. If you do not know what multipart download is , please do checkout my previous write up multipart-download. This comes in handy if you are scripting a client side web application that needs to download a couple of objects that a pretty big in size. In my case, they were images of the range 5–15 mb. Which is pretty huge. It also helps you use your entire allocated bandwidth (uses all the allocated browser threads).</summary></entry><entry><title type="html">Multipart download and Byte Ranges</title><link href="https://suvanika.github.io/https://suvanika.github.io/Multipart-Download/" rel="alternate" type="text/html" title="Multipart download and Byte Ranges" /><published>2018-05-18T00:00:00+00:00</published><updated>2018-05-18T00:00:00+00:00</updated><id>https://suvanika.github.io/https://suvanika.github.io/Multipart-Download</id><content type="html" xml:base="https://suvanika.github.io/https://suvanika.github.io/Multipart-Download/">&lt;h3&gt;The why and how of it.&lt;/h3&gt;
&lt;blockquote&gt;Let's break down what happens when you click on a button to download a file online.  You happen to send a HTTP get request to the website's respective web server, requesting for the object, the website responds back with a &quot;200 OK&quot; , &quot;you're good to go&quot; , with the requested object in it's body. Our browser takes care of the requests and processing the responses (pretty smart-ass). You can track all of this by toggling the network tab on your browser's developer toolkit (ctrl + shift + I ).

Typically a server sends out the entire object packed into one response message that we download . What if we could split the entire object into fragments and download them simultaneously? Picture a queue infront of an ice-cream shop, it extends for a few couple of meters and the the time taken to serve a customer is a few minutes. Boy oh boy, that's gonna take you a while till you get your cone. What if, instead of one long queue, we had three counters serving three parallel queues at the same rate?  This is what multipart download does in a nutshell. Break, grab concurrently , piece it back together and give it back to you, voila. We all use download managers to get our downloading done in a fast and efficient way, don't we? This is the underlying principle.

Now how do get this done?&lt;/blockquote&gt;
&lt;h2&gt; &lt;strong&gt;Range Byte Requests&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;HTTP protocol supports what is called a Range Byte request.  We add an extra &lt;code&gt;Range&lt;/code&gt; header to our http request.  The format is &lt;code&gt;Range : bytes= 0-1000&lt;/code&gt; or &lt;code&gt;Range : bytes=100-200/2700 &lt;/code&gt;  where (2700 is the size of the object). Also known as &lt;strong&gt;byte serving,  &lt;/strong&gt;range requests help you request for just a portion of a file , instead of downloading the entire file. This is very helpful while streaming large files, especially video files, one could skip to portions they wish to view without having to wait for the entire file to download. All you have to do is send a byte request for that portion of the video they wish to view. It serves useful while downloading a lot of files or while viewing pdf applications, you download just the portion that you are currently viewing and nothing more!&lt;/p&gt;

&lt;p&gt;The server has to support range requests as well. You could check this by sending a head request. Which requests only for the headers of the response excluding the content.  You can check this out by using cURL, a command line tool.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cURL -X -i -H &quot;Range :bytes=0-100&quot; &quot; http://demo8127239.mockable.io/h&quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Is translated into :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GET hi HTTP/1.1
Host: demo8127239.mockable.io
Range: bytes=0-100 &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Server responds back with a&lt;/p&gt;

&lt;p&gt;&lt;code&gt; 200 OK
Accept-Range : bytes &lt;/code&gt; if range requests are supported.
or else, it responds with a&lt;/p&gt;

&lt;p&gt;&lt;code&gt; 200 OK
Accept-Range :none&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;However if a GET request is placed we get either a &lt;code&gt; 200 OK &lt;/code&gt;
response if range bytes isn’t supported  or a &lt;code&gt;206 Partial Content &lt;/code&gt; status.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HTTP/1.1 206 Partial Content&lt;/code&gt;
&lt;code&gt;Content-Range: bytes 0-100/343
Content Length :343
Content-Type :application/json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The server sends out the entire file instead if it doesn’t support range bytes.&lt;/p&gt;

&lt;p&gt;Multiple range requests can also be placed together&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Range :bytes=0-100, 200-300&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BROWSER SUPPORT:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Browsers place a restriction on the number of concurrent TCP connections one might establish with a particular server. The list of browsers and their limit is given below.&lt;/p&gt;
&lt;table class=&quot;table thin-table&quot; border=&quot;1&quot; summary=&quot;&quot; rules=&quot;all&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;&gt;&lt;caption&gt;&lt;span class=&quot;tablecap&quot;&gt; Maximum supported connections&lt;/span&gt;&lt;/caption&gt;
&lt;thead class=&quot;thead&quot; style=&quot;text-align: left;&quot;&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;th id=&quot;d116953e124&quot; class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot;&gt;Version&lt;/th&gt;
&lt;th id=&quot;d116953e127&quot; class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot;&gt;Maximum connections&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody class=&quot;tbody&quot;&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Internet
Explorer&lt;sup&gt;®&lt;/sup&gt;&lt;/span&gt; 7.0&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Internet
Explorer&lt;/span&gt; 8.0 and 9.0&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Internet
Explorer&lt;/span&gt; 10.0&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Internet
Explorer&lt;/span&gt; 11.0&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Firefox&lt;sup&gt;®&lt;/sup&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Chrome™&lt;/span&gt;&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Safari&lt;sup&gt;®&lt;/sup&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Opera&lt;sup&gt;®&lt;/sup&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;iOS&lt;sup&gt;®&lt;/sup&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class=&quot;row&quot;&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e124 &quot;&gt;&lt;span class=&quot;ph&quot;&gt;Android™&lt;/span&gt;&lt;/td&gt;
&lt;td class=&quot;entry cellrowborder&quot; style=&quot;text-align: left; vertical-align: top;&quot; headers=&quot;d116953e127 &quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This restriction is placed since multiple connections to the same server might lead to flooding of requests and this might lead the server into thinking that this is a DDoS attack (denial of service attack).&lt;/p&gt;
&lt;h1&gt;Why multipart&lt;/h1&gt;
&lt;p&gt;I get that the number of chunks you can download concurrently is limited, and the limit is pretty meagre, so how beneficial can it actually be?
Most servers treat each connection uniquely and allocates bandwidth to it. When we make several connections to a server at once, each connection is treated as an individual unique connection and is allocated the same bandwidth. So what happens now, is that the server is pushing out more data to the same user at a given time. So how’s that for beneficial huh?
Although many users requesting several connections could overload the server or mislead the server into thinking it is under attack, this is where the built in browser restrictions come into place, although there are workarounds around this,(firefox) where the user gets to set the limit.
Also when the server from where you are requesting content is placed all the way on the other side of the planet, this adds latency to the response, (i.e, the propogation delay). In such a scenario, the bits transmitted in multipart trumps the delay, so yay! It also depends heavily on your internet connection, your bandwidth, the distance between you and the requested server and the bandwidth of the server (that’s a lot of factors coming into play). However multipart download helps save you time by utilizing the entire bandwidth as long as you have download requests lined up and this is what makes range bytes a better option than our single stream/channel download.
Most download managers support what is called dynamic fragmenting or segmentation, where threads are spawned for each byte range (in an application, the number of parallel threads set by default is 8, for a browser extension, it depends on the number of parallel connections the browser supports , view the above table to see your browser’s capacity), if a thread frees up, the segment yet to be downloaded or a thread whose download is in progress is dynamically fragmented in a such a way that the total bandwidth is used all the time. This speeds up your download process.&lt;/p&gt;
&lt;p id=&quot;81fb&quot; class=&quot;graf graf--p graf-after--p&quot;&gt;Also range byte request comes to the rescue if your download fails mid way. You don’t have to download the entire file all over again , you just pick off where you left off.&lt;/p&gt;
&lt;p id=&quot;87ca&quot; class=&quot;graf graf--p graf-after--p&quot;&gt;Since the size of each chunk is going to be way lesser than the actual file when sent, the chances of bit errors creeping on to your packet is less.&lt;/p&gt;
&lt;p id=&quot;1753&quot; class=&quot;graf graf--p graf-after--p&quot;&gt;Pretty cool huh?&lt;/p&gt;
&lt;p id=&quot;81db&quot; class=&quot;graf graf--p graf-after--p&quot;&gt;But wait.&lt;/p&gt;
&lt;p&gt;There might be one teeny tiny drawback. When a range header is set, the browser sends what is called a &lt;strong&gt;preflight request. This is done to check if the range header and the requested method is allowed on the server side CORS  (Cross Origin Resource Sharing) specification. The actual request is placed only after an OPTIONS response is received that explicitly states that the requested method and header is allowed. &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;access-control-allow-headers :range //&lt;strong&gt;accept requests with the range header and process it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;access-control-allow-methods :DELETE,GET,PATCH,POST,PUT,OPTIONS //&lt;strong&gt;accept only those requests for the given methods.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;access-control-allow-origin : * //&lt;strong&gt;accept request from any client &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This was brought about to prevent CSRF attacks.  Yay for user’s security, nay for multipart downloading, since each byte request has to go through the preflight - OPTIONS response process which adds substantial overhead. :(&lt;/p&gt;
&lt;h1&gt;Getting over this.&lt;/h1&gt;
&lt;p&gt;Browsers don’t tend to send preflight requests as long as the generated HTTP request is a simple one. Now what categorizes as simple  ?&lt;/p&gt;

&lt;p&gt;If the following methods are used:&lt;/p&gt;
&lt;ul class=&quot;postList&quot;&gt;
	&lt;li id=&quot;0583&quot; class=&quot;graf graf--li graf-after--p&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; title=&quot;The HTTP GET method requests a representation of the specified resource. Requests using GET should only retrieve data.&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;GET&lt;/a&gt; ,&lt;/code&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; title=&quot;The HTTP HEAD method requests the headers that are returned if the specified resource would be requested with an HTTP GET method. Such a request can be done before deciding to download a large resource to save bandwidth, for example.&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;HEAD&lt;/a&gt; ,&lt;/code&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; title=&quot;The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header.&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;POST&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the following headers are used:&lt;/p&gt;
&lt;ul class=&quot;postList&quot;&gt;
	&lt;li id=&quot;bcca&quot; class=&quot;graf graf--li graf-after--p&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; title=&quot;The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Type response header. Browsers set adequate values for this header depending of the context where the request is done: when fetching a CSS stylesheet a different value is set for the request than when fetching an image, video or a script.&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Accept&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;eb41&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; title=&quot;The Accept-Language request HTTP header advertises which languages the client is able to understand, and which locale variant is preferred. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Language response header. Browsers set adequate values for this header according their user interface language and even if a user can change it, this happens rarely (and is frown upon as it leads to fingerprinting).&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Accept-Language&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;6d5c&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; title=&quot;The Content-Language entity header is used to describe the language(s) intended for the audience, so that it allows a user to differentiate according to the users' own preferred language.&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Content-Language&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;ab17&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; title=&quot;The Content-Type entity header is used to indicate the media type of the resource.&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Content-Type&lt;/a&gt;&lt;/code&gt; (but note the additional requirements below)&lt;/li&gt;
	&lt;li id=&quot;b187&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; href=&quot;http://httpwg.org/http-extensions/client-hints.html#dpr&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;DPR&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;336a&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; href=&quot;http://httpwg.org/http-extensions/client-hints.html#downlink&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Downlink&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;1638&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; href=&quot;http://httpwg.org/http-extensions/client-hints.html#save-data&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Save-Data&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;44b4&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; href=&quot;http://httpwg.org/http-extensions/client-hints.html#viewport-width&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Viewport-Width&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;0318&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--li-anchor&quot; href=&quot;http://httpwg.org/http-extensions/client-hints.html#width&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Width&lt;/a&gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p id=&quot;f3af&quot; class=&quot;graf graf--p graf-after--li&quot;&gt;Only if the &lt;code class=&quot;markup--code markup--p-code&quot;&gt;&lt;a class=&quot;markup--anchor markup--p-anchor&quot; title=&quot;The Content-Type entity header is used to indicate the media type of the resource.&quot; href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Content-Type&lt;/a&gt;&lt;/code&gt; header has any of the following values:&lt;/p&gt;

&lt;ul class=&quot;postList&quot;&gt;
	&lt;li id=&quot;30fc&quot; class=&quot;graf graf--li graf-after--p&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;application/x-www-form-urlencoded&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;8598&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;multipart/form-data&lt;/code&gt;&lt;/li&gt;
	&lt;li id=&quot;98e9&quot; class=&quot;graf graf--li graf-after--li&quot;&gt;&lt;code class=&quot;markup--code markup--li-code&quot;&gt;text/plain&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ME : But how do we bypass the range header? &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Byte Ranges with URL : Bypass range header you say,  say no more fam.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;byte ranges can be set in the url :
&lt;code&gt;http://host/dir/foo;bytes=0-499 //requesting for the first 500 bytes
http://host/dir/foo;bytes=0-99,500-1499,-200 // multiple range requests , first hundred bytes, bytes from 500 to 1500 and the last 200 bytes
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Again, the server must support this.&lt;/p&gt;

&lt;p&gt;Even if it doesn’t multipart download makes a difference while downloading files of large size. So if you ask me, I’d say multipart for the win !&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;</content><author><name></name></author><summary type="html">The why and how of it. Let's break down what happens when you click on a button to download a file online.  You happen to send a HTTP get request to the website's respective web server, requesting for the object, the website responds back with a &quot;200 OK&quot; , &quot;you're good to go&quot; , with the requested object in it's body. Our browser takes care of the requests and processing the responses (pretty smart-ass). You can track all of this by toggling the network tab on your browser's developer toolkit (ctrl + shift + I ).</summary></entry></feed>