-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,76 @@ | ||
node-jsondir | ||
============ | ||
|
||
A NodeJS package to convert JSON objects to directories and back again. | ||
A Node package to convert JSON objects to directories and back again. Directory structures can easily be represented by JSON. Why not provide a way to go back and forth between them? | ||
|
||
### Why? | ||
|
||
Doing large asynchronous file operations in Node is simply a pain in the ass. Callbacks nest and nest and nest until suddenly you're ten or twenty levels of indentation deep and you have no idea what the hell is going on. JSONdir helps alleviate your I/O stress by giving you simple and familiar tools to do large amounts of work efficiently. | ||
|
||
### Simple example | ||
|
||
var jsondir = require('jsondir'); | ||
|
||
jsondir.json2dir({ | ||
"-path": 'path/to/directory', | ||
"myfile": { | ||
"-content": 'Hello world!' | ||
}, | ||
"mydir": { | ||
"a": { | ||
"b": { | ||
"c": { | ||
"-type": 'd' | ||
} | ||
} | ||
}, | ||
"1": { | ||
"2": { | ||
"3": {} | ||
} | ||
} | ||
} | ||
}, function(err) { | ||
if (err) throw err; | ||
}); | ||
|
||
By running the code above, you get the following directory structure in your current working directory: | ||
|
||
path/ | ||
+-- to/ | ||
+-- directory/ | ||
|-- myfile | ||
+-- mydir/ | ||
|-- a/ | ||
| +-- b/ | ||
| +-- c/ | ||
+-- 1/ | ||
+-- 2/ | ||
+-- 3 | ||
|
||
### Installation | ||
|
||
Use npm. | ||
|
||
npm install jsondir | ||
|
||
### Usage | ||
|
||
* Files and directories (and symlinks) are represented as nested JSON nodes with filenames as keys and children and attributes as properties. | ||
* Attributes are prefixed with a hyphen (`-`), which distinguish them from children. | ||
* If a node has no children and the `-type` or `-content` attributes are not explicitly specified, JSONdir will make that node into a file. Otherwise, it will make it into a directory. | ||
* All file operations are asynchronous. Love your callbacks. | ||
|
||
### Attributes | ||
|
||
Each node can have a variety of attributes: | ||
|
||
* `-type`: `-` (or `f`) for files, `d` for directories, `l` for symlinks. See Usage for behavior when omitted. | ||
* `-path`: Normally used on the origin node, this attribute is for specifying the file path of the directory structure. | ||
* `-mode`: Use octal/decimal numbers or a 9-character string like `rwxr-xr-x` for file mode. | ||
* `-umask`: Use octal/decimal numbers for file umask. Hint: The umask on Unix systems is usually `18` (`022`). Use `2` for sharing writing with the group. | ||
* `-owner`: Use for specifying the owner of the node, such as `dwieeb`. You may also use UIDs, like `1001`. | ||
* `-group`: Use for specifying the group of the node, such as `www-data`. You may also use GIDs, like `33`. | ||
* `-name`: In case you need to determine the filename at runtime, if this attribute is specified, it will be used for the filename instead of the node's key. | ||
* `-dest`: Specify the path of the symlink destination. If this attribute is specified, `-type` is assumed to be `l`. | ||
* `-content`: Specify the contents of the file. If this attribute is specified, `-content` is assumed to be `f`. |