本文整理汇总了TypeScript中fs.closeSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript closeSync函数的具体用法?TypeScript closeSync怎么用?TypeScript closeSync使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了closeSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: copyFile
function copyFile(sourceFile, destPath): void {
checkFileCopy(sourceFile, destPath);
var filename = path.basename(sourceFile);
if (fs.existsSync(destPath)) {
if (fs.lstatSync(destPath).isDirectory()) {
destPath += "/" + filename;
}
} else {
if (destPath[destPath.length - 1] === "/" || destPath[destPath.length - 1] === "\\") {
mkdirParentsSync(destPath);
destPath += filename;
} else {
mkdirParentsSync(path.dirname(destPath));
}
}
var bufLength = 64 * 1024;
var buff = new Buffer(bufLength);
var fdr = fs.openSync(sourceFile, "r");
var fdw = fs.openSync(destPath, "w");
var bytesRead = 1;
var pos = 0;
while (bytesRead > 0) {
bytesRead = fs.readSync(fdr, buff, 0, bufLength, pos);
fs.writeSync(fdw, buff, 0, bytesRead);
pos += bytesRead;
}
fs.closeSync(fdr);
fs.closeSync(fdw);
}
示例2: it
it('should not remove files if nothing is matched', () => {
fs.closeSync(fs.openSync(path.resolve(tmpDir, 'bar-123'), 'w'));
fs.closeSync(fs.openSync(path.resolve(tmpDir, 'bar-456'), 'w'));
fs.closeSync(fs.openSync(path.resolve(tmpDir, 'bar-789'), 'w'));
expect(removeFiles(tmpDir, [/zebra-.*/g])).toBe('');
expect(fs.readdirSync(tmpDir).length).toBe(3);
});
示例3: copyFile
function copyFile(fromPath: string, toPath: string) {
console.log("Copying from '" + fromPath + "' to '" + toPath);
makePathTo(toPath);
const fileSize = (fs.statSync(fromPath)).size,
bufferSize = Math.min(0x10000, fileSize),
buffer = new Buffer(bufferSize),
progress = makeProgress(fileSize),
handleFrom = fs.openSync(fromPath, "r"),
handleTo = fs.openSync(toPath, "w");
try {
for (;;) {
const got = fs.readSync(handleFrom, buffer, 0, bufferSize, null);
if (got <= 0) break;
fs.writeSync(handleTo, buffer, 0, got);
progress(got);
}
progress(null);
} finally {
fs.closeSync(handleFrom);
fs.closeSync(handleTo);
}
}
示例4:
var onDone = (err: Error) => {
remaining--;
if (remaining === 0) {
fs.closeSync(fd);
for (var type in outFds) {
fs.writeSync(outFds[type], '\n]\n');
fs.closeSync(outFds[type]);
}
console.log('finished!');
}
}
示例5: beforeAll
beforeAll(() => {
// create the directory
try {
fs.mkdirSync(tmpDir);
} catch (err) {
}
// create files that should be deleted.
fs.closeSync(fs.openSync(path.resolve(tmpDir, 'chromedriver_2.41'), 'w'));
fs.closeSync(
fs.openSync(path.resolve(tmpDir, 'chromedriver_foo.zip'), 'w'));
fs.closeSync(
fs.openSync(path.resolve(tmpDir, 'chromedriver.config.json'), 'w'));
fs.closeSync(fs.openSync(path.resolve(tmpDir, 'chromedriver.xml'), 'w'));
});
示例6: writeToBuffer
function writeToBuffer(filename, buffer) {
const fd = fs.openSync(filename, 'r');
const bytesRead = fs.readSync(fd, buffer, 0, buffer.length, 0);
fs.closeSync(fd);
return bytesRead;
}
示例7: function
fs.open (filepath, 'r', function (err, fd) {
if (!err) {
// File already exits
fs.closeSync (fd);
resolve (null);
}
else {
// File does not exist...create it
var fs_write_stream = fs.createWriteStream (filepath);
var gfs = Grid(conn.db);
//read from mongodb
var readstream = gfs.createReadStream ({_id: file._id});
readstream.pipe (fs_write_stream);
fs_write_stream.on ('close', function () {
console.log ('file created: ' + filepath);
resolve (null);
});
fs_write_stream.on ('error', function () {
err = 'file creation error: ' + filepath;
reject (err);
});
}
});
示例8: unlockChannelLock
function unlockChannelLock(): void {
'use strict';
if (channelLockFileDescriptor !== undefined) {
fs.closeSync(channelLockFileDescriptor);
channelLockFileDescriptor = undefined;
}
}
示例9: writeFileSync
export function writeFileSync(path: string, data: string | Buffer, options?: IWriteFileOptions): void {
const ensuredOptions = ensureWriteOptions(options);
if (ensuredOptions.encoding) {
data = encode(data, ensuredOptions.encoding.charset, { addBOM: ensuredOptions.encoding.addBOM });
}
if (!canFlush) {
return fs.writeFileSync(path, data, { mode: ensuredOptions.mode, flag: ensuredOptions.flag });
}
// Open the file with same flags and mode as fs.writeFile()
const fd = fs.openSync(path, ensuredOptions.flag, ensuredOptions.mode);
try {
// It is valid to pass a fd handle to fs.writeFile() and this will keep the handle open!
fs.writeFileSync(fd, data);
// Flush contents (not metadata) of the file to disk
try {
fs.fdatasyncSync(fd);
} catch (syncError) {
console.warn('[node.js fs] fdatasyncSync is now disabled for this session because it failed: ', syncError);
canFlush = false;
}
} finally {
fs.closeSync(fd);
}
}
示例10: done_cb
function done_cb(failed: boolean): void {
print((failed ? 'â' : 'â'));
if (failed) {
fs.writeSync(outfile, '\n');
}
fs.closeSync(outfile);
};