Understanding Streams | Understanding Node.js Core Concepts FREE VERSION

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ส.ค. 2024
  • Grab the complete and premium version of the course using this link:
    www.udemy.com/...
    Let's dive deep and understand all about Node.js Streams, one of the most important concepts every Node.js developer needs to master. We'll first understand how to use existing Writable Streams, then we'll learn how to develop our own Writable Streams, and then we'll move on to Readable Streams, and then Duplex Streams, and finally, we'll understand Transform Streams by creating a simple encryption/decryption application.
    Final Source Code: github.com/agi...
    The Course - Free Version: • Understanding Node.js ...
    Chapters:
    Understanding Writable Streams: 00:05:28
    Understanding Readable Streams: 1:51:42
    Understanding Stream Piping: 2:59:35
    Implementing Our Own Writable Stream: 3:51:13
    Implementing Our Own Readable Stream: 4:33:32
    Understanding & Implementing Duplex Streams: 4:53:21
    Understanding & Implementing Transform Streams: 5:09:38
    Outro: 5:48:30

ความคิดเห็น • 164

  • @viridianite
    @viridianite ปีที่แล้ว +82

    00:00 Introduction
    05:30 Code: Benchmarking different ways to write to a file
    31:18 Code: Benchmarking writing to a file using streams naively (faster but not memory efficient)
    38:05 What are streams in NodeJS? Explanation with analogies
    46:36 Different types of streams (with examples)
    53:10 How do writable streams work?
    1:01:05 How do readable streams work?
    1:04:16 Code: Using writable streams to make previous program more memory-efficient
    1:41:06 Reading NodeJS docs about writable streams and recap
    1:51:44 Code: Using readable and writable streams in conjunction
    2:12:45 Code: Selectively write chunk of data using streams
    2:21:32 Explanation of what's happening with numbers being split when chunking the data
    2:38:20 Code: Implementing the solution that solves the splitting issue
    2:54:36 Reading NodeJS docs about streams and recap
    3:02:16 Code: Example of piping
    3:25:38 Previous problem using piped streams
    3:31:36 Reading docs on pipes
    3:40:10 Why you shouldn't stream.pipe in production
    3:44:35 Example with stream.pipeline
    3:48:42 The stream.finished function for cleaning up
    3:49:18 Discussion about readable/writable streams, duplexes and transformers
    3:51:15 Implementing our own writable stream
    4:34:00 Implementing our own readable stream
    4:53:22 Duplex and transform streams
    5:09:38 Creating an encryption and decryption application
    5:48:35 Done with streams: Final notes, advice, stream-based NPM packages, etc.

  • @viridianite
    @viridianite ปีที่แล้ว +3

    Simply the fact you backed yourself into a corner and then walked yourself and the viewer through a possible solution, instead of using a cookie-cutter example, places you above the rest. And this is leaving out the fact you're such a good pedagogue.

  • @ayushdedhia25
    @ayushdedhia25 ปีที่แล้ว +19

    I'm really glad that I found your channel randomly. By watching all of your previous nodejs videos I feel much more confident working with nodejs ❤

  • @ibrahimkaarich2192
    @ibrahimkaarich2192 10 หลายเดือนก่อน +7

    after watching this great tutorial i feel like i'm the best nodeJS developer in the world hhhhhh thank you so much really such GREAT GREAT GREAT Tutorial

  • @drac.96
    @drac.96 ปีที่แล้ว +8

    A video like this is an absolute TREASURE FOR LEARNING FUNDAMENTAL NODE CONCEPTS! Thank you very very much for creating helpful tutorials like this one. 😀

  • @henrmota
    @henrmota ปีที่แล้ว +3

    No words to describe this explanation. I already used streams, but having this understanding of how all works it's another level. Plus, if you are a full stack developer you can use this concepts in the front-end with web streams.

  • @keshavkumar2
    @keshavkumar2 ปีที่แล้ว +3

    It's rarely the time when we get to learn so much on one topic from one video. Thank you so much man. I am eagerly waiting for your next video.

  • @aizensoskue3880
    @aizensoskue3880 ปีที่แล้ว +1

    man you re a legend like you explained the hardest subject in node better than anyone I watched, going in depth on the underline implementation of streams thank you so much for the content

  • @AnonyMous-uh4so
    @AnonyMous-uh4so ปีที่แล้ว +2

    wow, a video last 6 hours, can't wait to enjoy it. Thank you so much

  • @AMAN-un7ji
    @AMAN-un7ji ปีที่แล้ว

    Man, mannnnn, maaannn!!!!! Seriously!! I have been looking for this for over a week and couldn't find thorough details about node stream. So much grateful for this 🙏🙏🙏🙏 Thank you

  • @hmmoniruzzaman8537
    @hmmoniruzzaman8537 ปีที่แล้ว +3

    Loved this series so far. Would also like to see a condensed crash course on the same topic.

  • @RifkiJones
    @RifkiJones ปีที่แล้ว +3

    WOW! 6 hours on streams! amazing stuff, well explained. keep up the good work

    • @Cododev
      @Cododev  ปีที่แล้ว

      Thanks, will do!

  • @shivangtripathi2369
    @shivangtripathi2369 ปีที่แล้ว +2

    Hey you are doing great work there is no content like this on youtube...
    It'll help a lot if continue this level content....

  • @DeamonTanki
    @DeamonTanki 10 หลายเดือนก่อน +1

    Amazing course understanding node js fundamentals and going in depth is what i like about your courses unlike other node js courses they just into using Express js and make everything unclear and abstracted thanks for your efforts it really changed my pov in node and backend fundamentals and if anyone is wondering ,I highly recommand this course watch plus code along with him and take notes ,Cant wait for you next one .

    • @Cododev
      @Cododev  9 หลายเดือนก่อน

      Much appreciated!

  • @mantuskinas
    @mantuskinas ปีที่แล้ว +5

    a minor bug at 1:29:25 - breaking the loop before incrementing the counter. It will result in some duplicate numbers - 2915, 5645, etc. The counter should be incremented before breaking the loop

    • @Cododev
      @Cododev  ปีที่แล้ว +2

      Thank you very much for mentioning this!

  • @bicube7529
    @bicube7529 ปีที่แล้ว +2

    it took me sometime, but i finished!! I really love your advice of looking into the source code of libraries and of nodejs itself. since I started your series I feel i can read the nodejs docs more confidently, before they were obscure to me lol.
    Erik Wendel has a bunch of videos with project with streams, but he explained superficially, for a slow learner like me, I was lost. Thanks to you i feel I understand streams now. I implemented the percentage thing of the encryption app. now I going to start your networking video and also watch the projects of erik wendel, this time, understanding what he is doing haha. thanks for the great content

  • @ShoppingBored
    @ShoppingBored ปีที่แล้ว

    Thank you for your detailed explanation on what happens internally. I couldn't wrap my head around streams by just looking at the sample codes online.

  • @adhi14058
    @adhi14058 ปีที่แล้ว

    OMG WOW.! I have been trying to understand streams for so long, I have never came across such a detailed video on streams till date. YOU ARE A GEM. I really really appreciate what you are doing and request you to keep posting more videos when you get time. Love from India.!

  • @emmajennnings5920
    @emmajennnings5920 9 หลายเดือนก่อน

    Your voice is truly expressive and wonderful. It's very gentle and easy to absorb. A slight improvement would be to create engaging slides before diving into code demonstrations. That would be even better

    • @Cododev
      @Cododev  9 หลายเดือนก่อน

      Thanks Emma! I'll keep that in mind!

  • @dannydai1
    @dannydai1 10 หลายเดือนก่อน

    the most intensive nodejs stream course. thanks for sharing.

  • @ManojKumar-ti8rn
    @ManojKumar-ti8rn 9 หลายเดือนก่อน

    I thank you very much for this tutorial. Glad that I found you channel. Learned a lot from you. Hope you are doing good and please please don't stop this series, waiting to learn more from you

  • @bicube7529
    @bicube7529 ปีที่แล้ว

    man i am excited to begin this journey, already watched all the previous videos, let's gooo

    • @Cododev
      @Cododev  ปีที่แล้ว

      Keep it up buddy! Glad you’re learning so much!

  • @quoccuong1733
    @quoccuong1733 ปีที่แล้ว

    Stream has always been i topic that interests me the most. This will be great for revising my knowledge and learning smt new along the way!!

  • @vindecode5837
    @vindecode5837 ปีที่แล้ว

    You deserve to have a million subscriber lucky to find this video

  • @vishalbhalothia
    @vishalbhalothia ปีที่แล้ว +1

    Wawww.... Worth waiting for a long time 👏👏👏

  • @vorname1485
    @vorname1485 15 วันที่ผ่านมา

    37:24 you spin up 10_000_000 writes and prevent the buff from being freed as long as the write is not completed. This instantiation is a killer.

  • @codingwithpi
    @codingwithpi ปีที่แล้ว

    you are awesome I never see any tutorail on internet using approch for learning like you use. Just go deeper and deeper.

  • @MDABEDAFNAN
    @MDABEDAFNAN 5 หลายเดือนก่อน

    More than a nodeJS tutorial.You are the best

  • @akmalraj121
    @akmalraj121 ปีที่แล้ว

    Thank you so much ! I have learned a lot from this video about streams. And the way you explained each and every concepts is AMAZING !

  • @VaIrMp
    @VaIrMp 9 หลายเดือนก่อน

    thank you for your tutorials!! please continue making such high quality videos! really a treasure!

  • @davealma88
    @davealma88 11 หลายเดือนก่อน

    Great videos, explained in a manner for all public.

  • @maxime-oger
    @maxime-oger ปีที่แล้ว

    Thank you for all your efforts explaining those concepts that seems hard to master at first glance. Your videos make the understanding of node core concepts much more easy and this is great quality content and plus, for free. You are thrully contributing to make the world better

  • @jj342
    @jj342 ปีที่แล้ว

    This is a long one. I am 3hr in. Very good content!

  • @linearz
    @linearz 7 หลายเดือนก่อน

    The emphasize to use pipeline() instead of pipe() is very important.

  • @kartikmishra3940
    @kartikmishra3940 ปีที่แล้ว

    Wow...kindly dnt make us wait for these type of awesome videos...kindly keep loading❤️❤️

  • @exe.m1dn1ght
    @exe.m1dn1ght ปีที่แล้ว

    Wow i just found a hidden diamond, im gonna watch all of this !!

  • @PiroCoder
    @PiroCoder ปีที่แล้ว +2

    this is epic
    i like your teaching style by giving examples and optimizing as max as possible
    from where you learnt this much 😁

    • @Cododev
      @Cododev  ปีที่แล้ว +4

      Aww thanks! Well just experience and a good deal amount of research and experimentation!

  • @ching5070
    @ching5070 2 หลายเดือนก่อน

    on 5:30:13, the 92 which is 5c in hexa is the result from the operation: 1116 % 256 = 92

  • @omidsoleimani3817
    @omidsoleimani3817 ปีที่แล้ว

    wow... it's there, can't wait to watch it, thank you.

  • @tharlinhtet97
    @tharlinhtet97 ปีที่แล้ว

    It's a very important topic of CS.Great great great thank to you.

  • @s.m.golamkibriashourav7545
    @s.m.golamkibriashourav7545 ปีที่แล้ว

    You made a 6 hours+ video on stream!!! Thank you.

  • @puzzledl
    @puzzledl ปีที่แล้ว

    i'm really glad that see this video about nodejs stream

  • @aungmoethu1835
    @aungmoethu1835 ปีที่แล้ว

    thank you so much for the tutorial. This helps me understand streams a lot.

  • @funkdoc2001
    @funkdoc2001 2 หลายเดือนก่อน

    would love to see a video explaining how express builds upon node

  • @khattasallaman337
    @khattasallaman337 ปีที่แล้ว

    You're the best bro,
    Thanks for this series.

  • @andriibulbuk3434
    @andriibulbuk3434 9 หลายเดือนก่อน

    Thank you, your course is extremely helpful!

  • @Joseph-ex4sf
    @Joseph-ex4sf 10 หลายเดือนก่อน +1

    Thank you for making this available to all for free. Your content is very high quality - far better than the Node.js content on paid platforms like Pluralsight. Do you have a link to donate directly without giving 30% to TH-cam?

    • @Cododev
      @Cododev  9 หลายเดือนก่อน

      Thank you very much Joseph! I don't have a link for donations, but if you want, you could purchase the new version of the course using my link from the latest TH-cam video. Udemy will give 97% of the revenue to the instructor if a purchase is made using the link. Otherwise, the instructor only gets 37%, so that would be a great support! Thanks again!

    • @Joseph-ex4sf
      @Joseph-ex4sf 9 หลายเดือนก่อน

      @@Cododev Just purchased it. It's the least I can do. I've learned a lot already! Very few instructors go as deep as you do on the material. You rock man. Looking forward to seeing what comes next.

  • @dbzfan2487
    @dbzfan2487 หลายเดือนก่อน

    bro lots of love for this.

  • @InvincibleMan99
    @InvincibleMan99 3 หลายเดือนก่อน

    Hats off brother.
    God bless you

  • @mithileshpandit1071
    @mithileshpandit1071 ปีที่แล้ว

    You deserve way more subscribers

  • @soniablanche5672
    @soniablanche5672 ปีที่แล้ว +1

    UTF-8 decoding a chunk only works if the characters are ascii characters ( 1 character = 1 byte ), anything else (example Chinese characters) uses more than 1 byte, so if you try to decode the chuck it can either throw an error or give you incorrect characters

    • @Cododev
      @Cododev  ปีที่แล้ว

      That’s an excellent point! I’ll soon add a description in the pinned comment and point this out. I should’ve said every ASCII character is 1 byte, not every utf-8 character. Thanks a lot for mentioning this!

    • @soniablanche5672
      @soniablanche5672 ปีที่แล้ว

      @@Cododev I've even noticed the Node documentation do this in their http request stream example where they immediately decode the chunks as utf8

    • @nsudhir_here
      @nsudhir_here ปีที่แล้ว

      Hii,
      It seems you're understanding how numbers are being split.
      I need a little bit to understand it. Can you help?

  • @mohamedmirghani1747
    @mohamedmirghani1747 ปีที่แล้ว

    Wow, another amazing video.
    Many thanks❤

  • @GoranCogic-wb2dp
    @GoranCogic-wb2dp ปีที่แล้ว +2

    2:24:00
    If im not mistaken, there is a possibility that last number in file can be split into two separate chunks, so it is not certain that last item in last array is 'expected string number'?

  • @TheRealFishForReal
    @TheRealFishForReal ปีที่แล้ว

    This video is pure gold!

  • @cavidanbagiri7837
    @cavidanbagiri7837 ปีที่แล้ว

    OMG. What a u doing bro. this is just perfect. Greetings from Moscow

  • @sagarreddy7461
    @sagarreddy7461 11 หลายเดือนก่อน

    awesome explaination. GREAT WORK! Thank you :)

  • @zebedee788
    @zebedee788 11 หลายเดือนก่อน

    5:07:30 If your duplex.write is not writing to the file, make sure to add 'duplex.end(Buffer.from...) for the last line, to trigger the _final method. Happy coding

  • @niktwister
    @niktwister ปีที่แล้ว +1

    Hi , @ 04:57:40 you suggest that in case of transform stream , data chunks move from readable internal buffer to writable internal buffer. I think it should be the other way around , we write chunk to the writable internal buffer which then goes through the transform function where we push the transformed chunk to the readable internal buffer from where it can be consumed.

    • @Cododev
      @Cododev  ปีที่แล้ว +2

      That is an excellent point, thanks a lot for mentioning it! I’ll soon do an update and fix this, thanks again!

    • @niktwister
      @niktwister ปีที่แล้ว +1

      @@Cododev All thanks to you man for your efforts. Great videos 👍

  • @mikejames6452
    @mikejames6452 ปีที่แล้ว

    👍 Really helpful please continue making this type of content

  • @jackshephard7920
    @jackshephard7920 ปีที่แล้ว

    Thanks for the new year present!

  • @debrajash9376
    @debrajash9376 ปีที่แล้ว

    You are My God in human shape.

  • @serjio8781
    @serjio8781 11 หลายเดือนก่อน

    Great stuff!

  • @puupuuu9031
    @puupuuu9031 7 หลายเดือนก่อน

    During the "Implementing our own writable stream" section at 3:51:15, can some one verify that when subclassing the Writable class, the Writable class provides us an internal buffer and also manages it for us too. And that we don't actually have to implement/manage our own internal buffer in the subclass like we did there with the chunks array. tysm.

  • @hamzaguetioui6879
    @hamzaguetioui6879 ปีที่แล้ว

    thank you very mush for all the information you shared with us ,it really helpful 🙏🙏❤

  • @volodymyrvorona2250
    @volodymyrvorona2250 ปีที่แล้ว

    Another great video! Thank you!

  • @jsdepth
    @jsdepth ปีที่แล้ว

    One more Nodejs Core Concept ❤

  • @cstechnique
    @cstechnique ปีที่แล้ว +2

    Could you please restructure the course, create additional lecture slides, and publish them on Udemy? I have many questions to ask you, but on TH-cam, it's difficult to engage in a Q&A session because the platform lacks support for such interactions

    • @Cododev
      @Cododev  ปีที่แล้ว +2

      Hi there! That’s exactly what I’m doing right now. Unfortunately TH-cam is not the best platform to publish a 45h+ course on. At the end of the course, I’m also planning to give the students a massive real-world project with tens of thousands of lines of code and learn how to deploy that and see how every single part works together in production, and doing that is practically impossible on TH-cam. I have completed the next section of the course, but I’m now working on restructuring the course and moving it to a platform that’s dedicated to education and much more suitable for long-length courses. And you’re absolutely right, the TH-cam comments section is a pain for having excellent Q&A support. I will soon create a post and talk more about this. Thanks!

    • @cstechnique
      @cstechnique ปีที่แล้ว +1

      @@Cododev Dear Cododev, I felt incredibly happy when I discovered your lectures, and I admire your expertise in the world of Node.js. If you plan to publish a course on Udemy, possibly titled 'Understanding How Node.js Core Works in Depth,' I hope you'll take care to create beautifully designed lecture slides and provide detailed content. It would be great if after each lecture video, you could include a coding demonstration video to illustrate the concepts. If necessary, you can use the WhiteBoard application on Windows or a similar software on macOS for for additional visual aids.
      I prefer dark-themed slides over bright ones, as dark themes are more suitable for programmers, especially those with nearsightedness. If you feel that the course would benefit from teaching some foundational knowledge about C++ concurrency, C++ networking, and so on, I would be delighted if you could include those topics before proceeding with later parts of the course.
      Thank you!

  • @vineshdodiya1464
    @vineshdodiya1464 8 หลายเดือนก่อน

    Thanks so much for providing in depth explanation. ❤
    3:32:54 Is it good to use timeEnd in writeStream.on("finish") instead of readStream.on("end") ?

  • @whitebeardpirates7551
    @whitebeardpirates7551 ปีที่แล้ว

    WOOOOOOOOOOOW , thx for your efforts and time ♥♥

  • @gabrielmedeiros9806
    @gabrielmedeiros9806 ปีที่แล้ว

    man great content, congratulations!

  • @smrutiranjannayak2434
    @smrutiranjannayak2434 4 หลายเดือนก่อน

    Hey there!
    I was wondering if you could consider including your course in the Udemy subscription plan. It would be fantastic to have access to your content through such a convenient platform. Thanks for considering it!

    • @Cododev
      @Cododev  4 หลายเดือนก่อน +1

      Yes I’m looking forward to doing that, hopefully it will happen sometime soon if Udemy doesn’t require me to remove all the Node.js videos from the channel.

  • @mikhailsorokin7224
    @mikhailsorokin7224 ปีที่แล้ว

    Very important topic, thx!

  • @filipm5509
    @filipm5509 4 หลายเดือนก่อน

    Great job! Just bought your udemy course, keep it up! I´m wondering wht´s the name of the vscode theme in the video?

  • @zsling
    @zsling ปีที่แล้ว

    Really thanks for your video~❤

  • @atreeinthemoon
    @atreeinthemoon 5 หลายเดือนก่อน

    Hi, a very good video. can you tell me the font name in your code editor? It looks pretty.

  • @saiamarendrareddymandipati9965
    @saiamarendrareddymandipati9965 4 หลายเดือนก่อน

    Could you please create more videos in nodejs

  • @nsudhir_here
    @nsudhir_here ปีที่แล้ว

    1:22:46
    You said Buffer.alloc(16383, 10) doesn't mean we're writing 10 to the file and it was character "10" then also it would mean the same thing but in case of character it's writing to the file.

  • @RaGa_BABA
    @RaGa_BABA ปีที่แล้ว +2

    Hi question for readStream @2:40:00 , for the split issue. We are able to solve the issue where first number and last number of chunk are getting messed when we know the chunk array (all elements of chunk are in increasing order) but if we dont know the content of readStream chunk , how can we resolve this issue.

    • @Cododev
      @Cododev  ปีที่แล้ว +2

      Hi there! Well that's why it's important to understand the underlying format of the file you're dealing with! So suppose instead of a text file, it was an image file, then you would need to know how the pixels and colours are represented in binary so that you could do some modifications like applying filters, cropping, resizing, etc.
      In this example we made use of the fact that numbers are in ascending order, but honestly, for each problem you will need a specific solution that works best for that. So if you could maybe narrow your question down a bit, I might be able to explain better what to do in that specific situation. Thanks!

    • @gabrielmachado5391
      @gabrielmachado5391 ปีที่แล้ว +1

      a chunk just support 65536 bytes. if it has just 2 bytes lefting to full it, and the last string have 5 bytes, then the string will be splitted, two bytes would left behing to the previous chunk and the another three bytes will to the next chunk.
      Then, to solve you problem, you can see the full chunk to see the content of the chunk and then do some action based on what you need.
      see the full chunk content logging:
      console.log('------------staring chunk------------')
      console.log(chunk.toString())
      console.log('------------ending chunk------------')

    • @RaGa_BABA
      @RaGa_BABA ปีที่แล้ว

      @@Cododev Hi thanks for the reply.. I'm not a developer or programmer..its just a hobby so I might not be able to frame question very accurately.
      Suppose I'm reading a large mkv file from server how can I write it into another file without messing the data.is it possible without using pipe.Am I suppose to know the mkv formate
      One more question other than this😅. In readstream the default highwaterMark is 64 KiB and for the writeStream its 16KiB..my question is when data event is fired the Read stream has 64KiB data but write Stream can only take upto 16Kib before it needs to drain so does the 48KiB data rest into memory or how does it play out..does write stream writes into destination file in 3 chunks(16* 3 = 48) or all the 48KiB data gets written at once before reading another chunk.

    • @RaGa_BABA
      @RaGa_BABA ปีที่แล้ว

      @@gabrielmachado5391 thanks for the input gabriel..but if we don't know the underlying format how can we spot where the error has occurred that we need to fix by adding the last byte of previous chunk with the first byte of next chunk

    • @gabrielmachado5391
      @gabrielmachado5391 ปีที่แล้ว

      @@RaGa_BABA in node docs, they explain that chunk could be either a buffer or a string.
      otherwise, to catch errors you can use the 'error' event.
      descripition of this event, according the docs:
      "The 'error' event may be emitted by a Readable implementation at any time. Typically, this may occur if the underlying stream is unable to generate data due to an underlying internal failure, or when a stream implementation attempts to push an invalid chunk of data.
      The listener callback will be passed a single Error object."

  • @memduhcevik
    @memduhcevik ปีที่แล้ว

    You're awesome bro

  • @ching5070
    @ching5070 2 หลายเดือนก่อน

    why on 4:32:16, number of drains is 480 while number of writes is 481? This hasn't account for the last write which flushed the remaining data

  • @alonsob4069
    @alonsob4069 ปีที่แล้ว

    Will you do an async video? (promises, callback, Promise class..., How it works...)

  • @georgigeorgiev3765
    @georgigeorgiev3765 ปีที่แล้ว

    THANK YOU!

  • @tenzl
    @tenzl 8 หลายเดือนก่อน

    4:32:36 How come you didn't have to call stream.end when you used your own implementation of a writable stream? also why is there +2 more writes than drains? doesn't it call drain every time you write?

  • @genatokarev810
    @genatokarev810 ปีที่แล้ว

    Another approach to solve the 'drain event' problem is to use a generator. It will let us avoid keeping the "i" variable in the closure and you can safely break the loop. Next time you run it, it'll continue from where the generator yielded the last value bc it can save its state.
    const fs = require('fs').promises;
    function* bufferGenerator() {
    for (let i = 0; i < 1000000; i++) {
    yield Buffer.from(` ${i} `, 'utf-8');
    }
    }
    async function writeToFile() {
    console.time('write many');
    const fileHandle = await fs.open('./text.txt', 'w');
    const stream = fileHandle.createWriteStream();
    const generator = bufferGenerator();
    const writeMany = () => {
    let result = generator.next();
    while (!result.done) {
    if (!stream.write(result.value)) {
    break;
    }
    result = generator.next();
    }
    if (result.done) {
    stream.end();
    }
    };
    writeMany();
    stream.on('drain', writeMany);
    stream.on('finish', () => {
    console.timeEnd('write many');
    fileHandle.close();
    });
    }
    writeToFile().catch(console.error);

  • @gabrielmachado5391
    @gabrielmachado5391 ปีที่แล้ว +1

    Starting it on february 12.

    • @gustavo3220
      @gustavo3220 ปีที่แล้ว +1

      did you finish?

    • @gabrielmachado5391
      @gabrielmachado5391 ปีที่แล้ว +1

      Just finished it on february 22, now it's time to start practicing and getting better :D

    • @gustavo3220
      @gustavo3220 ปีที่แล้ว +1

      oloco dog

    • @Joao-oo8yj
      @Joao-oo8yj ปีที่แล้ว +1

      ​@@gabrielmachado5391 Leia a documentação brother, faça muitos testes mirabolantes que uma hora você fica craque. Faz até de olho fechado kkkk

  • @oppranto
    @oppranto 5 หลายเดือนก่อน

    I am Windows user, with ryzen 5600U. When i tried to run the "splitting chunk 2:38:00 " code with 10^9 size file, memory and Cpu work as it is, but disk r/w become too low, may be around 10-20MB. But in your code whenever you execute that code, your disk r/w go up to 1GB. One more thing is, if i perform stream write() operation with chunk, outside the foreach loop, disk r/w become high up to 800MB. Please help, me how to increase this disk w/r speed. This 10^9 file took at least 39minit to add all the even number in "dest.txt" file in my system.

  • @remarkablejames
    @remarkablejames ปีที่แล้ว

    Bro, you're the best 👌

  • @RaGa_BABA
    @RaGa_BABA ปีที่แล้ว

    great stuff, a question though @01:22:04 , if we allocate internal stream lets say 16383 bytes (writablelength = 16383) and then we allocate same stream a single byte but with setTimeout , the writableLenght is just one byte.
    for example:
    stream.write(Buffer.alloc(16383, "a"));
    console.log(stream.writableLength); // 16383
    setTimeout(function () {
    stream.write(Buffer.alloc(1, "b"));
    console.log(stream.writableLength); // 1 ---why?
    }, 1000);

    • @Cododev
      @Cododev  ปีที่แล้ว +2

      Well, it could be because this example is not really considered an example of repeated writes. We are writing once to the file (assuming it is a file stream), and then there's some time for the stream to flush the data to the underlying resource because of that setTimeout.
      So after the first write, Node sees the setTimeout, and then the main execution thread is done. And after a little while, the main execution thread will kick in again and handle the second write (learn about the event loop please if this doesn't make sense). I'm not sure but I think when we are going to the next tick (stopping the execution thread and then starting it again), Node streams will do an automatic flushing and draining so that the write is now done and the internal buffer is empty again. Let me look more into this and I'll let you know if I find more info about it! Thanks for the question!

    • @RaGa_BABA
      @RaGa_BABA ปีที่แล้ว

      @@Cododev yeahhh..it makes sense.. thankyou for the detailed answer.

  • @quangle6084
    @quangle6084 ปีที่แล้ว

    Great video!

  • @abbasramees4238
    @abbasramees4238 ปีที่แล้ว

    Just commenting to get you more reach, upload more content, thank you

  • @56f5dbc3
    @56f5dbc3 11 หลายเดือนก่อน

    Where can i found more information? is there a roadmap?

  • @aliadel1723
    @aliadel1723 ปีที่แล้ว

    The best of the best ♥

  • @sanjaysanthosh7009
    @sanjaysanthosh7009 11 หลายเดือนก่อน

    Thank you bro❤

  • @andriibulbuk3434
    @andriibulbuk3434 9 หลายเดือนก่อน

    I'm encountering an issue with a write-many.js. When I write a series of simple indexes ranging from 0 to a set number of writes, I consistently find two instances of the number 103978. I checked every number while writing even numbers from a file named src.txt, and discovered that the source of the problem is within `src.txt’ itself, which contains two identical numbers (103978). What could be causing this duplication?

  • @funnysandcuties6518
    @funnysandcuties6518 2 หลายเดือนก่อน

    Please i can't find the video about buffers

  • @CoderAxiy
    @CoderAxiy 7 หลายเดือนก่อน

    What is the name of the background music?

  • @alphabee8171
    @alphabee8171 10 หลายเดือนก่อน

    41:50 Having more memory is not bad but for an operation that will happen only once or twice it's waste of resources. That's one good way to think about this imo.

    • @alphabee8171
      @alphabee8171 10 หลายเดือนก่อน

      53:17 First

    • @alphabee8171
      @alphabee8171 10 หลายเดือนก่อน

      01:20:32 second

    • @alphabee8171
      @alphabee8171 10 หลายเดือนก่อน

      1:31:37 third

    • @alphabee8171
      @alphabee8171 10 หลายเดือนก่อน

      2:50:20 fourth

  • @madhuvarun2790
    @madhuvarun2790 ปีที่แล้ว

    Hi I have a doubt. Please look at the below code.
    const Stream = require("stream");
    const readableStream = new Stream.Readable({
    highWaterMark: 200,
    read() {},
    });
    readableStream.push("H");
    readableStream.on("data", (chunk) => {
    console.log(chunk.toString());
    });
    In above code, I mentioned the internal buffer size as 200. I pushed only the letter H onto the stream.
    According to the tutorial at 1:02:14, data event is raised only when internal buffer is filled. But the above code is printing the letter H(meaning - data event is raised before buffer is filled).
    Could someone explain me please?

  • @RaGa_BABA
    @RaGa_BABA ปีที่แล้ว

    Hello..got one more question from @3:21:08..(I hope you create a discord server or something😅)
    when I copy using below code it doesnt produce any null/weird characters in the des.txt file and it's faster as well..why??
    let buffer = Buffer.alloc(16384);
    let stats = await readhandle.stat();
    let itrs = stats.size / 16384;
    for (let i = 0; i < itrs; i++) {
    let data = await readhandle.read(buffer, 0, 16384, null);
    writehandle.write(data.buffer);
    }

  • @SANJIBNATH1
    @SANJIBNATH1 8 หลายเดือนก่อน

    I'm not finding the course on nodejs process