0.2.1 • Published 9 years ago
documark-cache v0.2.1
Documark Cache
Documark helper functions for working with cache files.
When running var cache = require('documark-cache')(document);
the following happens:
- The cache helper will use given
document
for resolving paths - A cache folder (
.documark/
) will be created in your document directory - This directory will also be set as WkHTMLToPDF its
--cache-dir
Usage
Load cache helper:
var cache = require('documark-cache')(document);
Use the cache helper in your plugins:
module.exports = function pluginNameHere ($, document, cb) { var cache = require('documark-cache')(document); // Folder path: var folderPath = cache.folderPath(); // Path to <document root>/.documark/ // File path: var filePath = cache.filePath('myfile.json'); // Path to <document root>/.documark/myfile.json // Read file: var file = cache.fileReadStream('my-cache-file.json'); file.on('data', function (chunk) { ... }); file.on('end', function () { ... }); file.resume(); // Or pipe to other stream: file.pipe(other); // Write to file: var file = cache.fileWriteStream('my-cache-file.json'); file.end(JSON.stringify({ hello: 'world!' }); cb(); };
Note: Use file.path
to get read/write stream its file path.