Method Description:
Sync version of Fs.write (). Writes a file (according to the file descriptor).
Grammar:
Copy Code code as follows:
Fs.writesync (fd, buffer, offset, length[, position])
Fs.writesync (FD, data[, position[, encoding])
Because this method belongs to the FS module, it is necessary to introduce FS module (VAR fs= require ("FS") before use.
Receive parameters:
FD file descriptor.
Buffer buffers, the data will be written. The size of the buffer size is set preferably at a multiple of 8, with high efficiency.
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.
Encoding (String) character encoding
Example:
Copy Code code as follows:
Fs.writesync (fd, buffer, offset, length[, position])
var fs = require (' FS ');
Fs.open (' Content.txt ', ' a ', function (ERR,FD) {
if (err) {
throw err;
}
var data = ' 123123123 Hello world ';
var buf = new Buffer (8);
Fs.writesync (FD, buf, 0, 8, 0);
Fs.close (Fd,function (err) {
if (err) {
throw err;
}
Console.log (' file closed ');
})
})
Fs.writesync (FD, data[, position[, encoding])
var fs = require (' FS ');
Fs.open (' Content.txt ', ' a ', function (ERR,FD) {
if (err) {
throw err;
}
var data = ' 123123123 Hello world ';
Fs.writesync (FD, data, 0, ' utf-8 ');
Fs.close (Fd,function (err) {
if (err) {
throw err;
}
Console.log (' file closed ');
})
})
Source:
Copy Code code as follows:
Usage
Fs.writesync (fd, buffer, offset, length[, position]);
OR
Fs.writesync (FD, string[, position[, encoding]);
Fs.writesync = function (fd, buffer, offset, length, position) {
if (util.isbuffer (buffer)) {
if (util.isundefined (position))
Position = NULL;
Return Binding.writebuffer (FD, buffer, offset, length, position);
}
if (!util.isstring (buffer))
Buffer + = ';
if (util.isundefined (offset))
offset = null;
Return binding.writestring (FD, buffer, offset, length, position);
};