Abstract type

Classes

Methods

static
copy(source, dest)

Copies a file.

Example

// import fs module
var fs = require('qminer').fs;
// open file to write
var fout = fs.openWrite('text.txt');
// close the stream
fout.close();
// copy the file
var destination = fs.copy('text.txt', 'copy.txt');

Parameters

Name Type Optional Description

source

string

 

Source file name.

dest

string

 

Destination file name.

static
del(fileName) → boolean

Deletes a file.

Example

// import fs module
var fs = require('qminer').fs;
// open file to write
var fout = fs.openWrite('delete.txt');
// close the stream
fout.close();
// delete the file
var destination = fs.del('delete.txt');

Parameter

Name Type Optional Description

fileName

string

 

File name.

Returns

boolean True if delete succeeded.

static
exists(fileName) → boolean

Checks if the file exists.

Example

// import fs module
var fs = require('qminer').fs;
// check if a file exists
fs.exists('text.txt');

Parameter

Name Type Optional Description

fileName

string

 

File name.

Returns

boolean True if file exists.

static
fileInfo(fileName) → module:fs~FileInfo

Returns the file info.

Example

// import fs module
var fs = require('qminer').fs;
// open file to write
var fout = fs.openWrite('text.txt');
// close the stream
fout.close();
// get the file info
var info = fs.fileInfo('text.txt');

Parameter

Name Type Optional Description

fileName

string

 

File name.

Returns

module:fs~FileInfo File info object.

static
listFile(dirName[, fileExtension][, recursive]) → Array of string

Returns a list fo files in the folder.

Example

// import fs module
var fs = require('qminer').fs;
// get the names of all files
var fileNames = fs.listFile('./');

Parameters

Name Type Optional Description

dirName

string

 

Folder name.

fileExtension

string

Yes

Results are filtered by file extension.

recursive

boolean

Yes

Recursively searches for file names if true.

Defaults to false.

Returns

Array of string Array of file names.

static
mkdir(dirName) → boolean

Creates a folder.

Example

// import fs module
var fs = require('qminer').fs;
// create a folder
var makeFolder = fs.mkdir('folder');

Parameter

Name Type Optional Description

dirName

string

 

Folder name.

Returns

boolean True if succeeded.

static
move(source, dest)

Moves a file.

Example

// import fs module
var fs = require('qminer').fs;
// open file to write
var fout = fs.openWrite('text.txt');
// close the stream
fout.close();
// move the file
var destination = fs.move('text.txt', 'move.txt');

Parameters

Name Type Optional Description

source

string

 

Source file name.

dest

string

 

Destination file name.

static
openAppend(fileName) → module:fs.FOut

Open file in append mode and return file output stream.

Example

// import fs module
var fs = require('qminer').fs;
// open file to write
var fout = fs.openWrite('append_text.txt');
// close the stream
fout.close();
// open file in append mode
var foutAppend = fs.openAppend('append_text.txt');
// close the stream
foutAppend.close();

Parameter

Name Type Optional Description

fileName

string

 

File name.

Returns

module:fs.FOut Output stream.

static
openRead(fileName) → module:fs.FIn

Open file in read mode and return file input stream.

Example

// import fs module
var fs = require('qminer').fs;
// open file to write
var fout = fs.openWrite('read_text.txt');
// write to file
fout.write('This is awesome!');
// close the stream 
fout.close();
// open file to read
var fin = fs.openRead('read_text.txt');

Parameter

Name Type Optional Description

fileName

string

 

File name.

Returns

module:fs.FIn Input stream.

static
openWrite(fileName) → module:fs.FOut

Open file in write mode and return file output stream.

Example

// import fs module
var fs = require('qminer').fs;
// open file to write
var fout = fs.openWrite('write_text.txt');
// close the stream 
fout.close();

Parameter

Name Type Optional Description

fileName

string

 

File name.

Returns

module:fs.FOut Output stream.

static
readCsvLines(buffer, opts)

Reads a buffer, containing a CSV file, line by line and calls a callback for each line. The callback function accepts an array with the values of the current line.

Example

// import fs module
var fs = require('qminer').fs;
// open a csv file and read the lines

Parameters

Name Type Optional Description

buffer

Buffer

 

The Node.js buffer.

opts

Object

 

Options parameter.

Values in opts have the following properties:

Name Type Optional Description

onLine

function()

 

A callback that gets called on each line (for example: function (lineArr) {}).

onEnd

function()

 

A callback that gets returned after all the lines have been read.

delimiter

String

 

The delimiter used when parsing.

lineLimit

Number

 

The maximum number of lines read.

skipLines

Number

 

The number of lines that should be skipped before first calling the callback.

static
readLines(buffer, onLine, onEnd, onError)

Reads a buffer line by line and calls a callback for each line.

Example

// import fs module
var fs = require('qminer').fs;
// create a file and write some lines
var fout = fs.openWrite('poem.txt');
fout.write('I dig,\nYou dig,\nHe digs,\nShe digs,\nWe dig,\nThey dig.\n It\'s not a beautiful poem, but it\'s deep.');
fout.close();
// open the file in read mode
var fin = fs.openRead('poem.txt');
// read the file line by line and call functions
//var numberOfLines = 0;
//function onLine(line) {
//    console.log(line);
//    numberOfLines += 1;
//}
//function onEnd(line) {
//    console.log("Number of lines", numberOfLines);
//}
//function onError(err) {
//    console.log(err);
//}
//fs.readLines(fin, onLine, onEnd, onError);

Parameters

Name Type Optional Description

buffer

(String, module:fs.FIn, or Buffer)

 

Name of the file, input stream of a Node.js buffer.

onLine

function()

 

A callback that gets called on each line (for example: function (line) {}).

onEnd

function()

 

A callback that gets returned after all the lines have been read.

onError

function()

 

A callback that gets called if an error occurs.

static
rename(source, dest)

Renames a file.

Example

// import fs module
var fs = require('qminer').fs;
// open file to write
var fout = fs.openWrite('text.txt');
// close the stream
fout.close();
// rename the file
if (fs.exists('rename.txt')) {
   fs.del('rename.txt');
}
var destination = fs.rename('text.txt', 'rename.txt');

Parameters

Name Type Optional Description

source

string

 

Source file name.

dest

string

 

Destination file name.

static
rmdir(dirName) → boolean

Removes a folder.

Example

// import fs module
var fs = require('qminer').fs;
// create a folder
var makeFolder = fs.mkdir('folder');
// delete folder
if (makeFolder) {
   fs.rmdir('folder');
}

Parameter

Name Type Optional Description

dirName

string

 

Folder name.

Returns

boolean True if succeeded.

Abstract type

inner
FileInfo  Object

Information about the file.

Properties

Name Type Optional Description

createTime

string

 

Create time.

lastAccessTime

string

 

Last access time.

lastWriteTime

string

 

Last write time.

size

number

 

File size in bytes.