custom-file
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'Streamfs = require 'graceful-fs' #or require 'fs' CustomFile = require 'custom-file' fs.cwd = processcwd # what's the get current working directory function. fs.path = require 'path.js' # what's the path package. (>=abstract-file@0.5.4 supports) CustomFilesetFileSystemfs # and should set your filesystem first. File = CustomFileFileFolder = CustomFileFolder file = File './readme.md'load:trueread:trueconsolelog filecontents #<Buffer 23...> file = File './readme.md'load:trueread:truebuffer:falseconsolelog filecontents instanceof Stream #true filepipe processstdoutend:false #pipe to stdout(the stdout should be never closed.) file = Folder './'load:trueread:trueconsolelog filecontents #[<File "README.md">, <Folder "src">,...] file = Folder './'load:trueread:truebuffer:falseconsolelog filecontents instanceof Stream #true filepipe through2obj next nullaFileinspect+'\n'pipe processstdoutend:false file = CustomFile './readme.md' # the CustomFile can create the file or folder object base on the file path fileshouldbeinstanceof Filefile = CustomFile './' # Or use the AdvanceFile with same object. fileshouldbeinstanceof Folder AdvanceFile = require 'custom-file/lib/advance'file = AdvanceFile './readme.md'fileshouldbeinstanceof AdvanceFilefile = AdvanceFile './'fileshouldbeinstanceof AdvanceFile fileloadSync read:true # here can load manually. fileload read:true consolelog content
the following is javascript:
var through2 = ;var Stream = Stream;var fs = ;var CustomFile = ; fscwd = processcwd;CustomFile; var File = CustomFileFile; var Folder = CustomFileFolder; var file = File'./readme.md' load: true read: true; console; file = File'./readme.md' load: true read: true buffer: false; console; file; file = ; console; file = ; console; file; file = ; // create a file object.fileshouldbefile = ; // create a folder object.fileshouldbe var AdvanceFile = file = fileshouldbefile = fileshouldbe file;file;
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