<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Suvanika Senthil on Medium]]></title>
        <description><![CDATA[Stories by Suvanika Senthil on Medium]]></description>
        <link>https://medium.com/@suvanika?source=rss-bcbe0916a33d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UjKiPtiqIwXf7GMuW2U3Zg.jpeg</url>
            <title>Stories by Suvanika Senthil on Medium</title>
            <link>https://medium.com/@suvanika?source=rss-bcbe0916a33d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 03:09:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suvanika/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JavaScript in Angular 5]]></title>
            <link>https://medium.com/@suvanika/javascript-in-angular-5-78a432a8ce67?source=rss-bcbe0916a33d------2</link>
            <guid isPermaLink="false">https://medium.com/p/78a432a8ce67</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[image-to-video-conversion]]></category>
            <category><![CDATA[whammies]]></category>
            <dc:creator><![CDATA[Suvanika Senthil]]></dc:creator>
            <pubDate>Thu, 14 Jun 2018 04:48:04 GMT</pubDate>
            <atom:updated>2018-06-14T04:48:04.771Z</atom:updated>
            <content:encoded><![CDATA[<p>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.</p><p>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.</p><p>However Iwas riddled with the problem of using the javascript file in angular. :(</p><p>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</p><p>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 &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).</p><h3><em>So how did I do it</em></h3><p>Easy-peasy.</p><p>Add your javascript file to the assets folder.</p><p>Open up your angular-cli.json, and under scripts, add the location of your javascript file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*GzwzuEjuSuiw6fDdPzKPTA.png" /></figure><p>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:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*0NO_sgZ8e4xQKfnysuYOvg.png" /></figure><p>and now you are good to start using.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*aOWK64k9DsvPxrf6jgS_Lw.png" /></figure><p>That is how it’s done.</p><p>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. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78a432a8ce67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multipart download in angular 5]]></title>
            <link>https://medium.com/@suvanika/multipart-download-in-angular-5-179c1089f265?source=rss-bcbe0916a33d------2</link>
            <guid isPermaLink="false">https://medium.com/p/179c1089f265</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[forkjoin]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[multi-part-download]]></category>
            <dc:creator><![CDATA[Suvanika Senthil]]></dc:creator>
            <pubDate>Wed, 06 Jun 2018 04:43:29 GMT</pubDate>
            <atom:updated>2018-06-06T14:31:58.891Z</atom:updated>
            <content:encoded><![CDATA[<p>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 on <a href="https://medium.com/@suvanika/multipart-download-and-byte-ranges-b5d6b7577e95">multipart-download</a>.</p><p>Downloading via multipart comes in handy if you are scripting a client side web application that needs to download a couple of objects that’s pretty big in size. In my case, they were images of the range 5–15 mb. Which is kinda big in size. It also helps you use your entire allocated bandwidth (uses all the allocated browser threads).</p><h3>Writing a Service</h3><p>Create a service , say download-file.</p><p><strong><em>ng generate service download-file</em></strong></p><p>It gets auto imported to your app.module.ts, but do make sure. Include the service in the providers array.</p><blockquote>import {MultipartService} from ‘./download-file.service’;</blockquote><blockquote>@NgModule({</blockquote><blockquote>providers: [MultipartService]</blockquote><blockquote>bootstrap: [AppComponent]</blockquote><blockquote>})</blockquote><blockquote>export class AppModule { }</blockquote><p>Now that we are done with our app module , let’s switch over to our service.</p><p>Time to write our method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*kUzLluFJ0ZQg_8YYcZTxWw.png" /></figure><p>First we are declare the variable fileSize and assign it the size of the file we want to download. Don’t forget to initialize a variable url and pass the url to it.</p><p>We figure out the chunksize (bytes) by dividing the fileSize by the number of parallel download requests we need, in this case 5. You can set this.</p><p>We iterate over the number of chunks and store the corresponding start and end values of each chunk in the json object ‘chunks’.</p><p>Now we have to a set a HTTP header ‘range’ and pass in the byte ranges. So we append ‘<em>Range, rangeval</em>’ , where rangeval is a string that contains bytes=<strong><em>start</em></strong>-<strong><em>end, where start and end are numbers taken from the json object.</em></strong></p><p>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.</p><p>We append the url and set <em>httpheaders in the headers parameter of http get and push our http get requests into an array </em><strong><em>headers</em></strong><em>. Note: They don’t get executed now.</em></p><h3>Firing the Requests</h3><p>import { forkJoin } from ‘rxjs/observable/forkJoin’;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*_yh-gMqiHvHk8trj3mFJ0g.png" /></figure><p>forkjoin is an operator from the rxjs library. It helps execute multiple observables at once and emit their final values.</p><p>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.</p><p>We subscribe to it to acquire the final blob. We are using a module file-saver</p><p>Download it by using<strong><em> npm install file-saver .</em></strong></p><p>import { saveAs } from ‘file-saver/FileSaver’;</p><p>to save our blob to our file system in the desired format.</p><p>We’re invoking a method saveToFileSystem that does this for us. We pass in the entire blob as a parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*tMNsd4kOmnlcEm6ZULikRw.png" /></figure><p>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.)</p><p>So that’s it guys, now you can go ahead and procure your stuff in chunks. Happy chunking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=179c1089f265" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MultiPart Download and Byte Ranges.]]></title>
            <link>https://medium.com/@suvanika/multipart-download-and-byte-ranges-b5d6b7577e95?source=rss-bcbe0916a33d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5d6b7577e95</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular-4]]></category>
            <category><![CDATA[multipart-download]]></category>
            <category><![CDATA[http-request]]></category>
            <dc:creator><![CDATA[Suvanika Senthil]]></dc:creator>
            <pubDate>Tue, 22 May 2018 18:11:08 GMT</pubDate>
            <atom:updated>2018-06-26T07:26:42.819Z</atom:updated>
            <content:encoded><![CDATA[<h3>The why and how of it.</h3><blockquote><em>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 “200 OK” , “you’re good to go” , 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 ).</em></blockquote><blockquote><em>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.</em></blockquote><blockquote><em>Now how do get this done?</em></blockquote><h2>Range Byte Requests</h2><p>HTTP protocol supports what is called a Range Byte request. We add an extra Range header to our http request. The format is Range : bytes= 0-1000 or Range : bytes=100-200/2700 where (2700 is the size of the object). Also known as <strong>byte serving, </strong>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!</p><p>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.</p><p>cURL -X -i -H &quot;Range :bytes=0-100&quot; &quot; http://demo8127239.mockable.io/h&quot;</p><p>Is translated into :</p><p>GET hi HTTP/1.1<br> Host: demo8127239.mockable.io<br> Range: bytes=0-100</p><p>Server responds back with a</p><p>200 OK<br> Accept-Range : bytes if range requests are supported.<br> or else, it responds with a</p><p>200 OK<br> Accept-Range :none</p><p>However if a GET request is placed we get either a 200 OK <br> response if range bytes isn&#39;t supported or a 206 Partial Content status.</p><p>HTTP/1.1 206 Partial Content<br> Content-Range: bytes 0-100/343<br> Content Length :343<br> Content-Type :application/json</p><p>The server sends out the entire file instead if it doesn’t support range bytes.</p><p>Multiple range requests can also be placed together</p><p>Range :bytes=0-100, 200-300</p><p><strong>BROWSER SUPPORT:</strong></p><p>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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*4-7MXdOlF6fBtmsJSIaiSA.png" /></figure><p>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).</p><h2>Why multipart</h2><p>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?<br> 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?<br> 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.<br> 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.<br> 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.</p><p>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.</p><p>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.</p><p>Pretty cool huh?</p><p>But wait.</p><p>There might be one teeny tiny drawback. When a range header is set, the browser sends what is called a <strong>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.</strong></p><p>access-control-allow-headers :range //<strong>accept requests with the range header and process it.</strong></p><p>access-control-allow-methods :DELETE,GET,PATCH,POST,PUT,OPTIONS //<strong>accept only those requests for the given methods.</strong></p><p>access-control-allow-origin : * //<strong>accept request from any client</strong></p><p>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. :(</p><h2>Getting over this.</h2><p>Browsers don’t tend to send preflight requests as long as the generated HTTP request is a simple one. Now what categorizes as simple ?</p><p>If the following methods are used:</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET">GET</a> ,<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD">HEAD</a> ,<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST">POST</a></li></ul><p>If the following headers are used:</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept">Accept</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language">Accept-Language</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language">Content-Language</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type">Content-Type</a> (but note the additional requirements below)</li><li><a href="http://httpwg.org/http-extensions/client-hints.html#dpr">DPR</a></li><li><a href="http://httpwg.org/http-extensions/client-hints.html#downlink">Downlink</a></li><li><a href="http://httpwg.org/http-extensions/client-hints.html#save-data">Save-Data</a></li><li><a href="http://httpwg.org/http-extensions/client-hints.html#viewport-width">Viewport-Width</a></li><li><a href="http://httpwg.org/http-extensions/client-hints.html#width">Width</a></li></ul><p>Only if the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type">Content-Type</a> header has any of the following values:</p><ul><li>application/x-www-form-urlencoded</li><li>multipart/form-data</li><li>text/plain</li></ul><p>Cool.</p><p><strong>ME : But how do we bypass the range header?</strong></p><p><strong>Byte Ranges with URL : Bypass range header you say, say no more fam.</strong></p><p>byte ranges can be set in the url :<br> http://host/dir/foo;bytes=0-499 //requesting for the first 500 bytes<br> 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</p><p>Again, the server must support this.</p><p>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 !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5d6b7577e95" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>