Home >Web Front-end >JS Tutorial >Instructions for using the fs.createReadStream method in node.js_node.js
Method description:
Returns a readStream (file reading stream, input stream) object. (readable stream)
Grammar:
Since this method belongs to the fs module, the fs module needs to be introduced before use (var fs= require(“fs”) )
Receive parameters:
path: (string) The path of the file to be read
options: (object) The array object contains the following properties
If both start and end are included, it will start from 0.
Encoding can be in three formats: ‘utf8′, ‘ascii’, or ‘base64′.
If autoClose is false, file descriptors will not be closed, even if they report an error.
Better to turn it off and make sure there are no file descriptor leaks.
If autoClose is true (the default behavior), the file descriptor on error or end will be automatically closed.
Example:
This example will read the last 10 sections of a 100k file.
Source code: