New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

custom-file

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

custom-file

It abstracts the File and Folder classes, can be used on any virtual file system, and stream supports.

  • 0.5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

custom-file npm

Build Status Code Climate Test Coverage downloads license

the custom-file can be used on any virtual file system with stream supports.

Usage

you must call setFileSystem() the fs to CustomFile Before use it:

through2    = require 'through2'
Stream      = require('stream').Stream
fs          = require 'graceful-fs' #or require 'fs'
CustomFile  = require 'custom-file'

fs.cwd      = process.cwd    # what's the get current working directory function.
fs.path     = require 'path.js' # what's the path package. (>=abstract-file@0.5.4 supports)
CustomFile.setFileSystem(fs) # and should set your filesystem first.

File = CustomFile.File
Folder = CustomFile.Folder

file = File './readme.md', load:true, read:true
console.log file.contents #<Buffer 23...>
file = File './readme.md', load:true, read:true, buffer:false
console.log file.contents instanceof Stream #true
file.pipe process.stdout, end:false #pipe to stdout(the stdout should be never closed.)

file = Folder './', load:true, read:true
console.log file.contents #[<File "README.md">, <Folder "src">,...]
file = Folder './', load:true, read:true, buffer:false
console.log file.contents instanceof Stream #true
file.pipe through2.obj (aFile, enc, next)->next null, aFile.inspect()+'\n'
.pipe process.stdout, end:false

file = CustomFile './readme.md' # the CustomFile can create the file or folder object base on the file path
file.should.be.instanceof File
file = CustomFile './'          # Or use the AdvanceFile with same object.
file.should.be.instanceof Folder

AdvanceFile = require 'custom-file/lib/advance'
file = AdvanceFile './readme.md'
file.should.be.instanceof AdvanceFile
file = AdvanceFile './'
file.should.be.instanceof AdvanceFile

file.loadSync read:true # here can load manually.
file.load read:true, (err, content)->
  console.log content

the following is javascript:

var through2 = require('through2');
var Stream = require('stream').Stream;
var fs = require('graceful-fs');
var CustomFile = require('custom-file');

fs.cwd = process.cwd;
CustomFile.setFileSystem(fs);

var File = CustomFile.File;

var Folder = CustomFile.Folder;

var file = File('./readme.md', {
  load: true,
  read: true
});

console.log(file.contents);

file = File('./readme.md', {
  load: true,
  read: true,
  buffer: false
});

console.log(file.contents instanceof Stream);

file.pipe(process.stdout, {
  end: false
});

file = Folder('./', {
  load: true,
  read: true
});

console.log(file.contents);

file = Folder('./', {
  load: true,
  read: true,
  buffer: false
});

console.log(file.contents instanceof Stream);

file.pipe(through2.obj(function(aFile, enc, next) {
  return next(null, aFile.inspect() + '\n');
})).pipe(process.stdout, {
  end: false
});

file = CustomFile('./readme.md'); // create a file object.
file.should.be.instanceof(File)
file = CustomFile('./'); // create a folder object.
file.should.be.instanceof(Folder)

var AdvanceFile = require('custom-file/lib/advance')
file = AdvanceFile('./readme.md')
file.should.be.instanceof(AdvanceFile)
file = AdvanceFile('./')
file.should.be.instanceof(AdvanceFile)

file.loadSync({read: true});
file.load({read: true}, function(err, content) {
  console.log(content);
});

API

See the abstract-file.

Changes

v0.5

  • [AbstractFolder] add the filter property to filter the files.

v0.4

  • abstract-folder class.

TODOs

  • LRUCache-able supports(not yet)
  • abstract file information class
  • abstract file operation ability
    • abstract save supports: I have no idea about this. I need more thinking. how to pass it to stream?
    • rename
    • create
    • append
    • delete

License

MIT

Keywords

FAQs

Package last updated on 20 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc