Method Description:
Sync version of Fs.read ().
method returns a bytesread (number of bytes read)
Grammar:
Copy Code code as follows:
Fs.readsync (fd, buffer, offset, length, position)
Because this method belongs to the FS module, it is necessary to introduce FS module (VAR fs= require ("FS") before use.
Receive parameters:
Fs
Buffer buffers, the data will be written.
Offsets to offset buffer writes
Length (integer) specifies how long the file reads bytes
Position (integer) specifies the starting position of the file read and, if it is null, reads the data from the position of the current file pointer.
Example:
Copy Code code as follows:
var fs = require (' FS ');
Fs.open (' 123.txt ', ' R ', function (ERR,FD) {
if (err) {
Console.error (ERR);
Return
}
var buf = new Buffer (8);
var ReadFile = Fs.readsync (fd, buf, 0, 8, NULL);
Console.log (ReadFile);
})
Source:
Copy Code code as follows:
Fs.readsync = function (fd, buffer, offset, length, position) {
var legacy = false;
if (!util.isbuffer (buffer)) {
Legacy String Interface (fd, length, position, encoding, callback)
Legacy = true;
var encoding = arguments[3];
assertencoding (encoding);
Position = arguments[2];
length = arguments[1];
Buffer = new buffer (length);
offset = 0;
}
var r = binding.read (fd, buffer, offset, length, position);
if (!legacy) {
return R;
}
var str = (R > 0)? Buffer.tostring (encoding, 0, R): ';
return [STR, r];
};