当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fs.readSync函数代码示例

本文整理汇总了TypeScript中fs.readSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readSync函数的具体用法?TypeScript readSync怎么用?TypeScript readSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了readSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: read

 protected read(fd: number, buf: any, size: number): number {
   let file = this.fileMap[fd];
   let buffer = new Buffer(size);
   let readed = fs.readSync(fd, buffer, 0, size, file.pos);
   unrar.HEAPU8.set(buffer, buf);
   file.pos += readed;
   return readed;
 }
开发者ID:YuJianrong,项目名称:nodejs-unrar,代码行数:8,代码来源:fileExtractor.ts

示例5: incbin

    incbin(filepath: string, offset?: number, len?: number): Data {
        if(typeof offset === 'undefined') { // incbin(filepath);
            return this.db(fs.readFileSync(filepath));

        } else if(typeof len === 'undefined') { // incbin(filepath, offset);
            if(typeof offset !== 'number')
                throw TypeError('Offset must be a number.');

            var fd = fs.openSync(filepath, 'r');

            var total_len = 0;
            var data: Buffer[] = [];
            const CHUNK = 4096;
            var buf = new Buffer(CHUNK);
            var bytes = fs.readSync(fd, buf, 0, CHUNK, offset);
            data.push(buf.slice(0, bytes));
            total_len += bytes;

            while((bytes > 0) && (total_len < bytes)) {
                buf = new Buffer(4096);
                bytes = fs.readSync(fd, buf, 0, CHUNK,  null);
                if(bytes > 0) {
                    data.push(buf.slice(0, bytes));
                    total_len += bytes;
                }
            }

            buf = Buffer.concat(data);
            // if(total_len > len) buf = buf.slice(0, len);

            fs.closeSync(fd);
            return this.db(buf);
        } else { // incbin(filepath, offset, len);
            if(typeof offset !== 'number')
                throw TypeError('Offset must be a number.');
            if(typeof len !== 'number')
                throw TypeError('Length must be a number.');

            var buf = new Buffer(len);
            var fd = fs.openSync(filepath, 'r');
            var bytes = fs.readSync(fd, buf, 0, len, offset);
            buf = buf.slice(0, bytes);
            fs.closeSync(fd);
            return this.db(buf);
        }
    }
开发者ID:streamich,项目名称:ass-js,代码行数:46,代码来源:PluginData.ts

示例6: processFiles

    private processFiles(onComplete: (status: number) => void, files: string[], program?: ts.Program) {
        const possibleConfigAbsolutePath = this.options.config != null ? path.resolve(this.options.config) : null;
        const linter = new Linter({
            fix: !!this.options.fix,
            formatter: this.options.format,
            formattersDirectory: this.options.formattersDirectory || "",
            rulesDirectory: this.options.rulesDirectory || "",
        }, program);

        let lastFolder: string | undefined;
        let configFile: IConfigurationFile | undefined;
        for (const file of files) {
            if (!fs.existsSync(file)) {
                console.error(`Unable to open file: ${file}`);
                onComplete(1);
                return;
            }

            const buffer = new Buffer(256);
            buffer.fill(0);
            const fd = fs.openSync(file, "r");
            try {
                fs.readSync(fd, buffer, 0, 256, 0);
                if (buffer.readInt8(0) === 0x47 && buffer.readInt8(188) === 0x47) {
                    // MPEG transport streams use the '.ts' file extension. They use 0x47 as the frame
                    // separator, repeating every 188 bytes. It is unlikely to find that pattern in
                    // TypeScript source, so tslint ignores files with the specific pattern.
                    console.warn(`${file}: ignoring MPEG transport stream`);
                    return;
                }
            } finally {
                fs.closeSync(fd);
            }

            const contents = fs.readFileSync(file, "utf8");
            const folder = path.dirname(file);
            if (lastFolder !== folder) {
                configFile = findConfiguration(possibleConfigAbsolutePath, folder).results;
                lastFolder = folder;
            }
            linter.lint(file, contents, configFile);
        }

        const lintResult = linter.getResult();

        this.outputStream.write(lintResult.output, () => {
            if (lintResult.failureCount > 0) {
                onComplete(this.options.force ? 0 : 2);
            } else {
                onComplete(0);
            }
        });

        if (lintResult.format === "prose") {
            // Check to see if there are any updates available
            updateNotifierCheck();
        }
    }
开发者ID:arusakov,项目名称:tslint,代码行数:58,代码来源:runner.ts

示例7: read

  read(offset: number, length: number): Buffer {
    let buf = new Buffer(length);
    if (length === 0) {
      // work around fs.readSync() error reading 0 bytes from
      // a 0-length buffer.
      // See https://github.com/nodejs/node-v0.x-archive/issues/5685
      return buf;
    }

    fs.readSync(this.fd, buf, 0, length, offset);
    return buf;
  }
开发者ID:pxpeterxu,项目名称:xar-js,代码行数:12,代码来源:io.ts

示例8: readFileSync

 readFileSync: function readFileSync(file: any, options: any) {
   setupManifest()
   const entry = manifest[file]
   if (!entry || !isString(file)) {
     return originalReadFileSync.apply(fs, arguments)
   }
   const [offset, length] = entry
   const resourceOffset = resourceStart + offset
   const encoding = isString(options) ? options : null
   const fd = fs.openSync(process.execPath, 'r')
   const result = Buffer.alloc(length)
   fs.readSync(fd, result, 0, length, resourceOffset)
   fs.closeSync(fd)
   return encoding ? result.toString(encoding) : result
 },
开发者ID:zavarat,项目名称:nexe,代码行数:15,代码来源:shim-fs.ts

示例9: tryReadFile

/** Read a file, but return undefined if it is an MPEG '.ts' file. */
async function tryReadFile(filename: string, logger: Logger): Promise<string | undefined> {
    const buffer = new Buffer(256);
    const fd = fs.openSync(filename, "r");
    try {
        fs.readSync(fd, buffer, 0, 256, 0);
        if (buffer.readInt8(0, true) === 0x47 && buffer.readInt8(188, true) === 0x47) {
            // MPEG transport streams use the '.ts' file extension. They use 0x47 as the frame
            // separator, repeating every 188 bytes. It is unlikely to find that pattern in
            // TypeScript source, so tslint ignores files with the specific pattern.
            logger.error(`${filename}: ignoring MPEG transport stream`);
            return undefined;
        }
    } finally {
        fs.closeSync(fd);
    }

    return fs.readFileSync(filename, "utf8");
}
开发者ID:erikkemperman,项目名称:tslint,代码行数:19,代码来源:runner.ts

示例10: Linter

const processFiles = (files: string[], program?: ts.Program) => {

    const linter = new Linter({
        formatter: argv.t,
        formattersDirectory: argv.s || "",
        rulesDirectory: argv.r || "",
    }, program);

    for (const file of files) {
        if (!fs.existsSync(file)) {
            console.error(`Unable to open file: ${file}`);
            process.exit(1);
        }

        const buffer = new Buffer(256);
        buffer.fill(0);
        const fd = fs.openSync(file, "r");
        try {
            fs.readSync(fd, buffer, 0, 256, null);
            if (buffer.readInt8(0) === 0x47 && buffer.readInt8(188) === 0x47) {
                // MPEG transport streams use the '.ts' file extension. They use 0x47 as the frame
                // separator, repeating every 188 bytes. It is unlikely to find that pattern in
                // TypeScript source, so tslint ignores files with the specific pattern.
                console.warn(`${file}: ignoring MPEG transport stream`);
                return;
            }
        } finally {
            fs.closeSync(fd);
        }

        const contents = fs.readFileSync(file, "utf8");
        const configuration = findConfiguration(possibleConfigAbsolutePath, file);
        linter.lint(file, contents, configuration);
    }

    const lintResult = linter.getResult();

    outputStream.write(lintResult.output, () => {
        if (lintResult.failureCount > 0) {
            process.exit(argv.force ? 0 : 2);
        }
    });
};
开发者ID:chrismbarr,项目名称:tslint,代码行数:43,代码来源:tslint-cli.ts


注:本文中的fs.readSync函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。