class static
fs. FIn
Source: fsdoc.
Used for reading files.
new FIn(fileName)
Input file stream.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// read a line
var str = fin.readLine();
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fileName |
string |
|
File name. |
Properties
eof
True if end of file is detected. Otherwise, false. Type boolean
.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// check if it's end of the file
var eof = fin.eof;
length
Length of input stream. Type number
.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// get the length of the document
var len = fin.length;
Methods
close()
Closes the input stream.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// close the stream
fin.close();
getCh() → string
Reads a character.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// get the next character
var char = fin.getCh();
- Returns
-
string
B Character string.
isClosed()
Checks if the input stream is closed.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// check if the stream is closed
var check = fin.isClosed();
peekCh() → string
Peeks a character.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// peek the next character
var char = fin.peekCh();
- Returns
-
string
B Character string.
readAll() → string
Reads the whole stream.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// get/read a the whole string
var all = fin.readAll();
- Returns
-
string
B Content of the file.
readJson() → Object
Reads json that was serialized using fs.FOut.writeJson
.
Example
// import fs module
var fs = require('qminer').fs;
// create and save a json and then read it using the readJson method
- Returns
-
Object
B Json object.
readLine() → string
Reads a line.
Example
// import module
var fs = require('qminer').fs;
// open file in write mode
var fout = fs.openWrite('file.txt');
// write sync and close
fout.writeLine('example text');
fout.close();
// open file in read mode
var fin = new fs.FIn('file.txt');
// get/read a new line
var line = fin.readLine();
- Returns
-
string
B Line string.
readString() → string
Reads a string that was serialized using fs.FOut.writeBinary
.
Example
// import fs module
var fs = require('qminer').fs;
// read a string that was serialized using fs.FOut.writeBinary
- Returns
-
string
B String.