Files
DefinitelyTyped/temp-fs/temp-fs-tests.ts
Radek Holý e6f19b91d0 Add definitions for temp-fs.
They don't want to include the definitions upstream thus I am publishing it at least here. See https://github.com/jakwings/node-temp-fs/pull/2
2015-11-09 11:15:37 +01:00

32 lines
919 B
TypeScript

// Copied from https://github.com/jakwings/node-temp-fs/blob/60a4d2586a81a7057bd4a395ec8c00b4100f84fe/README.md
// and slightly modified.
/// <reference path="temp-fs.d.ts" />
// Create a tempfile in the system-provided tempdir.
tempfs.open(function (err:any, file:tempfs.file) {
if (err) { throw err; }
console.log(file.path, file.fd);
// async
file.unlink(function () {
console.log('File delected');
});
// sync
// No problem even if unlink() is called twice.
file.unlink();
});
// Create a tempdir in current directory.
tempfs.mkdir({
dir: '.',
recursive: true, // It and its content will be remove recursively.
track: true // Track this directory.
}, function (err:any, dir:tempfs.dir) {
if (err) { throw err; }
console.log(dir.path, dir.recursive);
throw new Error('Since it is tracked, tempfs will remove it for you.');
dir.unlink();
});