Skip to content

mickelindahl/text_file_import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

Text file import

A small library use to import text data (ascii) from disk or over ftp in a directory with filter functionality

Installation

npm install git+ssh://git@github.com/mickelindahl/grassy_text_file_import.git

Usage

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    
        
    ] );

API

Adapter

Class used to import files from disk or over ftp

  • options object with the following keys
    • credentials sftp credential object with the following keys
      • host stirng THe sftp host url
      • portnumber sftp port to use
      • `user string User name for sftp
      • passwordstring 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 visible
    • files_filtered Filtered set of files
    • type 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

adapter.catch() ⇒ Adaptere

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 keys include true|false and visible true|false. include tells weather the file should be filtered out and visible tells weather it the file should be included in the this.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

ftpList() ⇒ promise

List files in directory over ftp

  • directory Directory to list files in
  • credentials ftp credentials
    • host host address
    • port host port to connect to
    • user user to login with
    • password password to login with
  • resolve promise resolve handler

Kind: global function
Returns: promise - list with files in directory

ftpRead() ⇒ promise

Read files over ftp

  • files List with files paths to read
  • encoding Type of encoding to read files with
  • credentials ftp credentials
    • host host address
    • port host port to connect to
    • user user to login with
    • password password to login with
  • resolve promise resolve handler

Kind: global function
Returns: promise - list with data from each file

Tests

Lab.cmd

Contributing

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.

Release History

  • 0.1.0 Initial release

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published