<?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 Zaingulbaz on Medium]]></title>
        <description><![CDATA[Stories by Zaingulbaz on Medium]]></description>
        <link>https://medium.com/@zaingulbaz8?source=rss-8aa86123cd18------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uf3-Cfp4l3IlM2B_7bZEew.jpeg</url>
            <title>Stories by Zaingulbaz on Medium</title>
            <link>https://medium.com/@zaingulbaz8?source=rss-8aa86123cd18------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:08:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zaingulbaz8/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[Buffers in Node JS]]></title>
            <link>https://medium.com/@zaingulbaz8/buffers-in-node-js-df51ee7b8fa3?source=rss-8aa86123cd18------2</link>
            <guid isPermaLink="false">https://medium.com/p/df51ee7b8fa3</guid>
            <dc:creator><![CDATA[Zaingulbaz]]></dc:creator>
            <pubDate>Thu, 28 Dec 2023 20:50:49 GMT</pubDate>
            <atom:updated>2023-12-29T10:33:15.309Z</atom:updated>
            <content:encoded><![CDATA[<p>In Node JS, we use buffers when we are dealing with binary data, text files, audios or videos. Buffers are also used while streaming the data.</p><p>A Buffer is essentialy a chunk of memory that is allocated outside of Javascript Engine to deal with binary data more effeciently.</p><p>Here are some key points to remember while using buffers in Node Js:</p><p><strong>1- Raw Data</strong></p><p>We can use buffers while dealing with raw data. The main advantage is that we donot need to change the encoding while dealing raw data using buffers.</p><p><strong>2-Fixed Size</strong></p><p>A fixed size buffer should be used when we know what will be the size of our data. In Node JS, we specify size of buffers in bytes.</p><pre>const myBuffer=Buffer.alloc(10);</pre><p>In the above code, we are specifying a buffer of 10 bytes. Using buffer of fixed size is a effecient way of using memory but again it depends on our usecase.</p><p><strong>3-Buffer Pool:</strong></p><p>Node JS essentialy used a pool of pre allocated memory for buffers. It helps to effectively manage memory.</p><p>In Node JS, Buffer is a global object so we donot need to import it every time we use.</p><p><strong>Methods of Buffer:</strong></p><p><strong>1-Buffer.from()</strong></p><p>We can convert any data into buffer by using .from() method in Buffer class. Let’s see how:</p><pre>const myBuffer= Buffer.from(&quot;hello&quot;,&quot;utf-8&quot;);<br>//output: &lt;Buffer 68 65 6c 6c 6f&gt;</pre><p>We can also change the encoding to binary, hex, ascii, latin1, etc.</p><p><strong>2-Buffer.byteLength(buffer):</strong></p><p>We can use .byteLength(buffer) method to calculate the size of any buffer in bytes, as we know 1 byte has 8 bits.</p><pre>const myBuffer=Buffer.from(&quot;hello&quot;);<br>const size=Buffer.byteLength(myBuffer);<br>//5 bytes</pre><p><strong>3-Buffer.concat(</strong>[buffer]<strong>):</strong></p><p>We can use .concat([buffer]) method to concatenate two buffers together. It is useful when you are getting data from two different sources in the form of buffers and you want to merge them together.</p><pre>const source1=Buffer.from(&quot;hello&quot;);<br>//&lt;Buffer 68 65 6c 6c 6f&gt;<br>const source2=Buffer.from(&quot;world&quot;);<br>//&lt;Buffer 77 6f 72 6c 64&gt;<br>const data= Buffer.concat([source1,source2]);<br>//&lt;Buffer 68 65 6c 6c 6f 77 6f 72 6c 64&gt;<br>const singleData=Buffer.from(&quot;helloworld&quot;);<br>//&lt;Buffer 68 65 6c 6c 6f 77 6f 72 6c 64&gt;</pre><p><strong>4-</strong> <strong>Buffer.toString(buffer,encoding):</strong></p><p>If we are dealing with buffers and want to change it to string with different encoding we can use .toString(buffer,encoding) method.</p><pre>const str= Buffer.from(&quot;hello&quot;).toString(&quot;hex&quot;);<br>//68656c6c6f</pre><p>In above examples, you can see that Buffers cannot only be used to temporarily store the data but we can also do data manipulation by using buffers in node js.</p><p>So if you are making any node application and gets frustrated with different encodings then give buffers a chance, they won’t disappoint you. ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df51ee7b8fa3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“this” keyword in javascript]]></title>
            <link>https://medium.com/@zaingulbaz8/this-keyword-in-javascript-2a784e29b7e5?source=rss-8aa86123cd18------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a784e29b7e5</guid>
            <dc:creator><![CDATA[Zaingulbaz]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 05:45:48 GMT</pubDate>
            <atom:updated>2023-07-20T05:45:48.958Z</atom:updated>
            <content:encoded><![CDATA[<p>Javascript is a programming language that behaves very differently when it comes to “this” keyword. In javascript we can use this keyword in:</p><p><strong>1-Objects:</strong></p><p>In case of objects “this” keyword refers to the keys of the object. If we consider following example, the print function uses “this” keyword and it refers to the scope of the object block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*3RX5iyV-khFpmt5Hti4TLA.png" /></figure><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*MtzW3PXmFcWDhA3gi8WChA.png" /></figure><p><strong>2-Normal Function:</strong></p><p>If we talk about normal function, “this” keyword can only be used if we bind any object with the function.</p><p>Consider the following example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*-WsX0CAaetYvny5ZMjUgog.png" /></figure><p>If we see the function abc, it is binded with the object that has the key “name”. The “this” keyword will refer to the object “<strong>obj</strong>” binded with function abc.</p><p>We cannot access global variables with “this” keyword inside the function. That’s why <strong>this.profession</strong> would print <strong>undefined</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*SBkM29dOEQequKimKn9jHQ.png" /></figure><p><strong>3- Arrow Functions:</strong></p><p>In case of arrow functions, “this” keyword refers to the window object by default. We cannot bind any object with an arrow function.</p><p>Consider the following code snippet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*Tb-LIOLEzFlK5wlsEB248w.png" /><figcaption>\</figcaption></figure><p>As we can see that the arrow function is able to access window object with “this” keyword.</p><p>If we talk about Node JS environment as we do not have any window object that’s why “this” keyword is of no use in arrow functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*hS-wYmmtwzaNYKb1GPeaFg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a784e29b7e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>