0.5.4 • Published 10 years ago
abstract-file v0.5.4
abstract-file 
It can be used on any virtual file system, and stream supports. Inspired by vinyl. Try to keep compatibility with vinyl.
- abstract file information class
- abstract property-manager to manage the file attributes.
- abstract file operation ability
- abstract load supports
- load read:true, buffer:true
- load stat
- load content
- abstract load supports
- abstract folder/directory supports: It's the array of file object and read-dir-stream
- abstract fs: It should apply via
AbstractFile.fs = fs- abstract cwd: It should apply via
fs.cwd = process.cwd - abstract path.js: It should apply via
fs.path = require('path.js')
- abstract cwd: It should apply via
Usage
the File and Folder implementation are in the custom-file package.
API
Properties
path(File|String): the file path. it will be internally stored as absolute path always.- It will get path string from the object's
pathattribute if it's an file object.
- It will get path string from the object's
cwd(String): the current working directroy.base(String): the base directory. used to calc the relative path. the default iscwdif it's empty.history(ArrayOf String): the history of the path changes.stat(Stat): the file stats object. theisDirectory()method be used.contents(String|Buffer|ArrayOf(File)|Stream): the contents of the file.- It's the array of
Fileobject or a read-dir-stream if the file is a folder.
- It's the array of
skipSize(Integer): the skipped length from beginning of contents. used bygetContent(). only for buffer.relative(String): readonly. the relative path frompathtobase.dirname(String): readonly. the dirname of thepath.basename(String): readonly. the basename of thepath.extname(String): readonly. the extname of thepath.
Methods
constructor([aPath, ]aOptions[, done])aPath(String): the file path. it will be stored as absolute path always.aOptions(Object):path(String): the same as theaPathargument.cwd(String): the current working directroy.base(String): the base directory. used to calc the relative path. the default iscwdif it's empty.load(Boolean): whether load file data(stat and contents). defaults to falseread(Boolean): whether load file contents. defaults to false. only forloadis true.buffer(Boolean): whether load file contents as buffer or stream, defaults to true. only available forloadandreadboth are true.text(Boolean): whether load file contents as text, defaults to false. only available forload,readandbufferboth are true.
done(Function): the callback function only available forloadis true.- the
loadSyncwill be used if nodonefunction.
- the
load(aOptions, done): Asynchronous load file stat and content.read(Boolean): whether load file contents. defaults to false.buffer(Boolean): whether load file contents as buffer or stream, defaults to true. only available forreadis true.text(Boolean): whether load file contents as text, defaults to false. only available forreadandbufferboth are true.doneFunction(err, content): the callback function. thecontentonly available whenreadis true
loadSync(aOptions): Synchronous load file stat and content.read(Boolean): whether load file contents. defaults to false.buffer(Boolean): whether load file contents as buffer or stream, defaults to true. only available forreadis true.text(Boolean): whether load file contents as text, defaults to false. only available forreadandbufferboth are true.- return contents only available when
readis true
loadContent(aOptions, done): Asynchronous load file contents.buffer(Boolean): whether load file contents as buffer or stream, defaults to true.reload(Boolean): whether force to reload the contents from the file. defaults to false.overwrite(Boolean): whether assign to this.contents after loading the contents from the file. defaults to true.doneFunction(err, content): the callback function.
loadContentSync(aOptions): Synchronous load file contents.buffer(Boolean): whether load file contents as buffer or stream, defaults to true.reload(Boolean): whether force to reload the contents from the file. defaults to false.overwrite(Boolean): whether assign to this.contents after loading the contents from the file. defaults to true.- return contents
getContent(aOptions, done): Asynchronous get the file contents buffer, skipSize used. only available for File(not for folder)text(Boolean): whether load file contents as text, defaults to false.doneFunction(err, content): the callback function.
getContentSync(aOptions): Synchronous get the file contents buffer, skipSize used. only available for File(not for folder)text(Boolean): whether load file contents as text, defaults to false.
loadStat(aOptions, done): Asynchronous load file stats.doneFunction(err, stat): the callback function.
loadStatSync(aOptions): Synchronous load file stats.- return stat
pipe(stream[, options]): pipe it to the stream.stream(Writable Stream): The destination stream for writing data.options(Object): Pipe optionsend(Boolean): End the writer when the reader ends. Default = true
validate(aFile, raiseError=true): the aFile object whether is valid.isDirectory(): whether is directory.isBuffer(): whether contents is buffer.isStream(): whether contents is stream.toString(): return the path.replaceExt(extname): return the replaced extname's path string.
these methods should be overrides:
- _validate(aFile): the aFile object whether is valid.
- _loadContentSync(aFile)
- _loadStatSync(aFile)
- _loadContent(aFile, done): optional
- _loadStat(aFile, done): optional
- _inspect()
Changes
v0.5
the dirname attribute should pass the path directly if the file is a folder.
if @isDirectory() @path else path.dirname @path
v0.4
- with new property-manager v0.10.0
- base object(prototypeOf) supports
- add overwrite option to getContent/getContentSync
- bug getContent should get loaded content as the buffer when text is false.
encoding(String) attribute if the contents is a text._contents(Buffer|Stream) internal attribute
- change the
contentsattribute to a dynamic attirbute.
- broken the loadContent return the
_contents(Buffer|Stream) now.
v0.3
- broken the default value of the
bufferoption istruenow.
- add the
reload,overwriteoption to loadContent/loadContentSync
- assign the
skipSizefrom options after loading.
- add
extNamereadonly property - add
replaceExtmethod to get the replaced extname's path string.
License
MIT
0.5.4
10 years ago
0.5.3
10 years ago
0.5.2
10 years ago
0.5.1
10 years ago
0.5.0
10 years ago
0.4.5
10 years ago
0.4.4
10 years ago
0.4.3
10 years ago
0.4.2
10 years ago
0.4.1
10 years ago
0.4.0
10 years ago
0.3.2
10 years ago
0.3.1
10 years ago
0.3.0
10 years ago
0.2.4
10 years ago
0.2.3
10 years ago
0.2.2
10 years ago
0.2.1
10 years ago
0.2.0
10 years ago
0.1.10
10 years ago
0.1.9
10 years ago
0.1.8
10 years ago
0.1.7
10 years ago
0.1.6
10 years ago
0.1.5
10 years ago
0.1.4
10 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago
0.0.0
10 years ago