Description of the fs. createReadStream method in node. js, createreadstream

Source: Internet
Author: User

Description of the fs. createReadStream method in node. js, createreadstream

Method description:

Returns a readStream (object reading stream, input stream) object. (Readable Stream)

Syntax:

Copy codeThe Code is as follows:
Fs. createReadStream (path, [options])

Because this method belongs to the fs module, we need to introduce the fs module (var fs = require ("fs") before use "))

Receiving parameters:

Path: (string) path of the file to be read

Options: (object) an array object contains the following attributes:

Copy codeThe Code is as follows:
{Flags: 'R ',
Encoding: null,
Fd: null,
Mode: 0666,
AutoClose: true
}

Options can use start and end to set the range of bytes that the file can read, rather than reading the entire file.

If both start and end are included, it starts from 0.

Encodeing can be 'utf8', 'ascii ', or 'base64.

If autoClose is false, the file descriptor will not be closed even if they report an error.

It is best to close it and ensure that there is no file descriptor leakage.

If autoClose is set to true (the default action), the file descriptor of the error or end is automatically disabled.

Example:

In this example, the last 10 10 bytes in a kb file are read.

Copy codeThe Code is as follows:
Fs.createReadStream('sample.txt ', {start: 90, end: 99 });

Source code:

Copy codeThe Code is as follows:
Fs. createReadStream = function (path, options ){
Return new ReadStream (path, options );
};

Related Article

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.