本文整理匯總了TypeScript中fs.close函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript close函數的具體用法?TypeScript close怎麽用?TypeScript close使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了close函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: spawnChildren
// called below
function spawnChildren(): void {
for (let i = 0; i < parsetree.length-1; i++) {
let cmd = parsetree[i];
let pout = pipes[i][1];
let opts = {
// pass our stdin, stdout, stderr to the child
stdio: [pin, pout, stderr],
};
let child = execute_child(cmd, opts, pids, codes);
fs.close(pipes[i][1]);
pin = pipes[i][0];
}
// execute last command with our stdout
let cmd = parsetree[parsetree.length-1];
let opts = {
// pass our stdin, stdout, stderr to the child
stdio: [pin, 1, stderr],
};
if (cmd[cmd.length - 1] === '&') {
cmd = cmd.slice(0, cmd.length - 1);
bg = true;
}
let child = execute_child(cmd, opts, pids, codes);
for (let i = 0; i < pipes.length; i++) {
fs.close(pipes[i][0]);
}
}
示例2: pipe2
pipe2((perr: any, rfd: number, wfd: number) => {
if (perr)
throw new Error('pipe2 failed: ' + perr);
let echo = child_process.spawn('/usr/bin/echo', ['hello world'], { stdio: [0, wfd, 2] });
echo.on('error', (err: any) => {
process.stderr.write('error: ' + err, () => {
exit = 1;
childFinished(err);
});
});
echo.on('exit', (code: number) => {
childFinished(null, code);
});
// XXX: we don't need the wfd at this point, and
// keeping it open seems to prevent cat from getting
// an EOF on the pipe?
fs.close(wfd, () => {
let cat = child_process.spawn('/usr/bin/cat', [], { stdio: [rfd, 1, 2] });
cat.on('error', (err: any) => {
process.stderr.write('error: ' + err, () => {
childFinished(err);
});
});
cat.on('exit', (code: number) => {
childFinished(null, code);
});
fs.close(rfd);
});
});
示例3: function
fs.read(fd, Buffer.alloc(length), 0, length, resourceOffset, function(
error: Error,
bytesRead: number,
result: Buffer
) {
if (error) {
return fs.close(fd, function() {
callback(error, null)
})
}
fs.close(fd, function(err: Error) {
if (err) {
return callback(err, result)
}
callback(err, encoding ? result.toString(encoding) : result)
})
})
示例4: async
FS.write(info.fd, contents, async (err) => {
if (err) {
reject(err)
} else {
resolve(await gen(info.path))
FS.close(info.fd, () => FS.unlink(info.path, () => { /*noop*/ }))
}
}))
示例5: reject
return new Promise<any>((resolve, reject) => {
fs.close(fd, (err: any) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
示例6: async
fs.write(fd, buffer, 0, buffer.length, null, (err) => {
if (err) throw 'Error writing file: ' + err;
fs.close(fd, async () => {
const objecthash = git.hashObject(dir, path.join('..', 'Temp', 'whatever'));
git.addToIndex(dir, objecthash, 'Assets/' + filename);
const treehash = git.writeTree(dir);
const sha = git.commitTree(dir, treehash, parenthash);
resolve(sha);
});
});
示例7: prependTextToFileSync
export function prependTextToFileSync(filePath: string, fileContent: string) {
if (isFileExists(filePath)) {
let data = fs.readFileSync(filePath); // read existing contents into data
let fd = fs.openSync(filePath, "w+");
let buffer = new Buffer(fileContent);
fs.writeSync(fd, buffer, 0, buffer.length, 0); // write new data
fs.writeSync(fd, data, 0, data.length, 0); // append old data
fs.close(fd);
}
}
示例8: function
fs.open(path, 'wx', function(oerr: any, fd: number): void {
if (oerr) {
// now we're in trouble and
// we should try other files instead.
code = 1;
let msg = pathToScript + ': ' + oerr + '\n';
process.stderr.write(msg, finished);
}
// thats it - close the sucker.
fs.close(fd, finished);
});
示例9: callback
fs.fdatasync(fd, (syncError: Error) => {
// In some exotic setups it is well possible that node fails to sync
// In that case we disable flushing and warn to the console
if (syncError) {
console.warn('[node.js fs] fdatasync is now disabled for this session because it failed: ', syncError);
canFlush = false;
}
return fs.close(fd, closeError => callback(closeError));
});
示例10:
inputStream.on('end', () => {
fs.close(files[name].handler, () => {
fs.unlink('server/temp/' + name, (err: Error) => {
if (err) {
throw err;
}
console.log('File deleted!');
// Emit a done event to alert the user
socket.emit('Done', { path: 'server/files/' + name, name: name });
});
});
});