當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs.closeSync函數代碼示例

本文整理匯總了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);
}
開發者ID:PlayFab,項目名稱:SDKGenerator,代碼行數:33,代碼來源:generate.ts

示例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);
 });
開發者ID:angular,項目名稱:webdriver-manager,代碼行數:7,代碼來源:file_utils.spec-int.ts

示例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);
    }
}
開發者ID:danielearwicker,項目名稱:mirrorball,代碼行數:25,代碼來源:mirrorball.ts

示例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!');
   }
 }
開發者ID:fcrick,項目名稱:tes-data,代碼行數:11,代碼來源:getAllByType.ts

示例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'));
 });
開發者ID:angular,項目名稱:webdriver-manager,代碼行數:14,代碼來源:clean.spec-int.ts

示例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;
}
開發者ID:nspragg,項目名稱:filesniffer,代碼行數:7,代碼來源:isbinary.ts

示例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);
				});
			}
		});
開發者ID:roderickmonk,項目名稱:rod-monk-sample-repo,代碼行數:25,代碼來源:ttcGridFS.ts

示例8: unlockChannelLock

function unlockChannelLock(): void {
	'use strict';
	if (channelLockFileDescriptor !== undefined) {
		fs.closeSync(channelLockFileDescriptor);
		channelLockFileDescriptor = undefined;
	}
}
開發者ID:data9824,項目名稱:SavannaTalk,代碼行數:7,代碼來源:main.ts

示例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);
	}
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:30,代碼來源:pfs.ts

示例10: done_cb

 function done_cb(failed: boolean): void {
   print((failed ? '✗' : '✓'));
   if (failed) {
     fs.writeSync(outfile, '\n');
   }
   fs.closeSync(outfile);
 };
開發者ID:dk-dev,項目名稱:doppio,代碼行數:7,代碼來源:test_runner.ts


注:本文中的fs.closeSync函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。