A small library use to import text data (ascii) from disk or over ftp in a directory with filter functionality
npm install git+ssh://git@github.com/mickelindahl/grassy_text_file_import.git
let ftp = new Adapter( {
credentials: {
host: process.env.HOST,
user: process.env.USER,
password: process.env.PASS,
},
type: 'ftp'
} )
ftp.list( 'a directory' )
.filter(
let include = ['list_files.txt'].indexOf( f.name ) != -1;
let lm = f.last_modified > moment( '2017-02-02' ).format( 'YYYY-MM-DD HH:mm' );
return {
include: include * lm,
exits: true})
.read( 'binary' )
.parse(parse.crews)
.then( data=>[
//do something with data
] );
Class used to import files from disk or over ftp
options
object with the following keyscredentials
sftp credential object with the following keyshost
stirng THe sftp host urlport
number sftp port to use- `user string User name for sftp
password
string Password for sftp user
files_visible
Files in the directory that are visible. Visibility can be controlled by the filter. Files that are included in the filter are always visiblefiles_filtered
Filtered set of filestype
string source type to import from disk|ftp
Kind: global class
adapter.then() ⇒ Adapter
Replicates promise then behavior for class
resolve
A value to resolve
Kind: instance method of Adapter
Replicates promise catch behavior for class
resolve
A value to resolve
Kind: instance method of Adapter
adapter.list() ⇒ Adapter
List the content in a directory
directory
string name of directory to import text files from
Kind: instance method of Adapter
adapter.filter() ⇒ Adapter
Apply filter to filters in directory. Date filter effects the this.files
attribute
whereas the onFileName filter does not.
filter
Function function({file object}) which should return a object with the keysinclude
true|false andvisible
true|false.include
tells weather the file should be filtered out andvisible
tells weather it the file should be included in thethis.files_visible
array.
Kind: instance method of Adapter
adapter.read() ⇒ Adapter
Reads file content from the disk
encoding
encoding to use when reading the file e.g. binary or utf8
Kind: instance method of Adapter
adapter.parse() ⇒ Adapter
Parse the into into json (could be any structure actually)
parse
function function([object]) where object has the keys
text
and file
. Text is the raw file content and file is the
filename. It returns a promise wHich resolves into the parsed data
Kind: instance method of Adapter
List files in directory over ftp
directory
Directory to list files incredentials
ftp credentialshost
host addressport
host port to connect touser
user to login withpassword
password to login with
resolve
promise resolve handler
Kind: global function
Returns: promise
- list with files in directory
Read files over ftp
files
List with files paths to readencoding
Type of encoding to read files withcredentials
ftp credentialshost
host addressport
host port to connect touser
user to login withpassword
password to login with
resolve
promise resolve handler
Kind: global function
Returns: promise
- list with data from each file
Lab.cmd
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
- 0.1.0 Initial release