11 MU class Network "Attack on node. JS Foundation (i)" Buffer and stream

Source: Internet
Author: User

Buffer

(logo.png)

The following code reads Logo.png as the buffer type
Then convert the buffer to a string
You can configure a string:data:image/png;Base64,Buffer.toString()

varFs= require(' FS ')FS.ReadFile(' Logo.png ',function(Err,Origin_buffer){    Console.Log(' origin_buffer If buffer format: '+Buffer.Isbuffer(Origin_buffer))//console.log (' Read to Origin_buffer: ' + origin_buffer)    //Create file    FS.WriteFile(' Log_buffer.png ',Origin_buffer,function(ERR){        if(ERR)Console.Log(ERR)})//var base84image = new Buffer (origin_buffer). toString (' base64 ')    //Convert to String    varBase64image= Origin_buffer.toString(' base64 ')Console.Log(' string base64image: ' +Base64image)varDecodedImage= New Buffer(Base64image, ' base64 ')//console.log (' encoded decodedimage: ' +decodedimage)    //console.log (' Compare origin_buffer and DecodedImage: ' + buffer.compare (origin_buffer,decodedimage))    FS.WriteFile(' Logo_decoded.png ',DecodedImage,function(ERR){        if(ERR)Console.Log(ERR)})})

11 MU class Network "Attack on node. JS Foundation (i)" Buffer and stream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.