## Child classes

FIn(fileName)

FOut(fileName[, append])

## Methods

copy(source, dest)
del(fileName)
exists(fileName)
fileInfo(fileName)
listFile(dirName[, fileExtension][, recursive])

mkdir(dirName)
move(source, dest)
openAppend(fileName)
openRead(fileName)
openWrite(fileName)

readCsvLines(buffer, opts)
readLines(buffer, onLine(line), onEnd(err))
rename(source, dest)
rmdir(dirName)

## Abstract type

FileInfo

## Classes

### FIn

### FOut

## 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`B 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`B 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`B 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`B 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`B 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`B 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`B 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`B Output stream.

static

### readCsvLines(buffer, opts)

Reads a buffer, containing a CSV file, line by line and calls a callback for each line. As specified in CSV format standard defined in RFC 4180 double-quotes (") can be used as escape characters. If a double-quote appears in a field, the field nust be enclosed in double-quotes and the double-quote appearing inside a field must be escaped by preceding it with another double quote. The callback function accepts an array with the values of the current line.

#### Example

    // import fs module
    let fs = require('qminer').fs;
    // create a file and write some lines
    let fout = fs.openWrite('test.csv');
    fout.write('name,movie\nGeorge Clooney,"O Brother, Where Art Thou?"\n"Sylvester ""Sly"" Stallone",Expendables');
    fout.close();
    // open the file in read mode
    let fin = fs.openRead('test.csv');
    // prepare callbacks for csv parsing
    // count the lines and for each line output the parsed cells
    let nLines = 0;
    function onLine(lineVals) {
        nLines += 1;
        console.log(lineVals);
        return true;
    }
    // at the end output the number of lines
    function onEnd(err) {
        if (err) { console.log("Error:", err); }
        console.log("Number of lines", nLines);
    }
    // parse the csv files
    fs.readCsvLines(fin, {
        "onLine": onLine,
        "onEnd": onEnd
    });

#### 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(line), onEnd(err))

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;
        return true;
    }
    function onEnd(err) {
        if (err) { console.log("Error:", err); }
        console.log("Number of lines", numberOfLines);
    }
    fs.readLines(fin, onLine, onEnd);

#### Parameters

Name | Type | Optional | Description
--- | --- | --- | ---
buffer | (String, module:fs.FIn, or Buffer) |  | Name of the file, input stream of a Node.js buffer.
onLine(line) | function() |  | A callback that gets called on each line (for example: `function (line) {}`). Function must return `true` to continue reading, else reading is stoped and `onEnd` is called.
onEnd(err) | function() |  | A callback that gets returned after all the lines have been read or function `onLine` returned `false`. If error was due to exception, the exception is provided in `err`.

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`B 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.