Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

wFiles

0.6.74 • Public • Published

wFiles Build Status Build status

Files manipulation library of middle level. Module offers several implementations of single interface, called ( FileProvider ) to perform file operations in the same manner with different sources/destinations.

Avaible operations:

  • File read/write operations.
  • Creating read/write steams.
  • Operations with file stats object.
  • File create,delete,rename,copy operations.
  • Making soft/hard links.

Installation

npm install wFiles

FileProvider.HardDrive

Allows files manipulations on local drive.

Declaration
var _ = wTools;
var provider = _.FileProvider.HardDrive();

FileProvider.Extract

Allows file manipulations on filesTree - object based on some folders/files tree, where folders are nested objects with same depth level as in real folder and contains some files that are properties with corresponding names and file content as a values.

Structure example:
var tree =
{
 "some_dir" :
 {
   'some_file.txt' : "content",
   'empty_dir' : {}
 }
}
Declaration
var _ = wTools;
var provider = _.FileProvider.Extract({ filesTree : tree });

Usage:

Example #1
/*Read file synchronously*/
var data = provider.fileRead
({
  pathFile : 'my_file',
  sync : 1
});
console.log( data );
 
/*Read file asynchronously*/
provider.fileRead({ pathFile : 'my_file' })
.got( function( err, data )
{
  if( err )
  throw err;
  console.log( data );
});
Example #2
/*Write to file synchronously*/
provider.fileWrite
({
  pathFile : 'my_file',
  data : 'some data'
})
 
/*Write to file asynchronously*/
provider.fileWrite
({
  pathFile : 'my_file',
  data : 'some data',
  sync : 0
})
.got( function( err )
{
  if( err )
  throw err;
  console.log( 'Success' );
});
Example #3
/*Create dir synchronously*/
provider.directoryMake( 'my_dir' );
 
/*Create dir asynchronously*/
provider.directoryMake
({
   pathFile : 'a',
   sync : 0
 })
.got( function( err )
{
  if( err )
  throw err;
  /*some code after dir creation*/
});
Example #4
/*Getting file stats object sync*/
/*error throwing is disabled by default, use throwing : 1 to turn on*/
var stats = provider.fileStat( 'my_dir' );
if( stats )
console.log( stats );
 
/*async*/
provider.fileStat
({
   pathFile : 'my_dir',
   throwing : 1,
   sync : 0
})
.got( function( err, stats )
{
  if( err )
  throw err;
  console.log( stats );
});
Example #5
/*Copy file sync*/
provider.fileCopy
({
  pathDst : 'my_file2',
  pathSrc : 'my_file'
});
 

install

npm i wFiles

Downloadsweekly downloads

3,785

version

0.6.74

license

MIT

repository

githubgithub

last publish

collaborators

  • avatar