How to use the read-chunk.sync function in read-chunk

To help you get started, we’ve selected a few read-chunk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elmadev / elmaonline-site / src / upload.js View on Github external
getReplaysByMd5(MD5).then(replaysMD5 => {
            if (replaysMD5.length > 0) {
              resolve({
                error: 'Duplicate',
                replayInfo: replaysMD5,
                file: filename,
              });
            } else {
              // find LevelIndex
              const replayCRC = readChunk.sync(
                `.${config.publicFolder}/temp/${uuid}-${filename}`,
                16,
                4,
              );
              let replayLevel = readChunk.sync(
                `.${config.publicFolder}/temp/${uuid}-${filename}`,
                20,
                12,
              );
              replayLevel = replayLevel.toString('utf-8').split('.')[0];
              getLevelsFromName(replayLevel).then(levels => {
                let LevelIndex = 0;
                levels.forEach(level => {
                  if (level.LevelData && replayCRC) {
                    if (
                      level.LevelData.toString('hex').substring(14, 22) ===
                      replayCRC.toString('hex')
                    ) {
                      LevelIndex = level.LevelIndex;
                    }
                  }
github citra-emu / citra-games-wiki / validation / app.js View on Github external
function validateImage(path, config) {
    if (fs.existsSync(path) === false) {
        validationError(`Image \"${path}\"' was not found at ${path}.`);
    } else {
        // Read first 12 bytes (enough for '%PNG', etc)
        const buffer = readChunk.sync(path, 0, 12);
        const type = imageType(buffer).mime;
        if (type !== config.type) {
            validationError(`Incorrect format of image (${type} != ${config.type})`);
        }

        let dimensions = sizeOf(path);

        for (const sizeIndex in config.sizes) {
            const size = config.sizes[sizeIndex];

            if (dimensions.width === size.width && dimensions.height === size.height) {
                return;
            }
        }

        // Build our error message
github vorg / kollektor / lib / generate-thumbnail.js View on Github external
function generateThumbnail (orig, thumb, w, callback) {
  log('Generate Thumbnail', orig)
  const buffer = readChunk.sync(orig, 0, 262)
  const extInfo = fileType(buffer)
  const ext = extInfo ? extInfo.ext : null
  if (!ext) {
    return callback(new Error('Unknown file type'), null)
  }
  if (ext === 'gif') {
    execFile(gifsicle, ['--resize', `${w / 2}x_`, orig, '-o', thumb], (err) => {
      callback(err, thumb)
    })
  } else { // jpeg, png
    jimp.read(orig)
      .then((img) => {
        log('jimp resize', w, thumb)
        img.resize(w, jimp.AUTO).getBuffer(jimp.MIME_JPEG, (err, buf) => {
          log('jimp resize done', err)
          fs.writeFileSync(thumb, buf)
github thammin / node-bpg / test / encoderSpec.js View on Github external
.map(file => {
      var buffer = readChunk.sync(file, 0, 4);
      t.true(isBpg(buffer));
    }).then(() => t.end());
  });
github audiojs / audio-type / cli.js View on Github external
help();
	return;
}

if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) {
	console.log(pkg.version);
	return;
}

if (process.stdin.isTTY) {
	if (!input) {
		help();
		return;
	}

	init(readChunk.sync(input, 0, 12));
} else {
	process.stdin.once('data', function (data) {
		init(data);
	});
}
github kube-HPC / hkube / core / api-server / lib / service / builds.js View on Github external
async _fileInfo(file) {
        const bufferExt = readChunk.sync(file.path, 0, fileType.minimumBytes);
        let fileExt = fileType(bufferExt);
        if (fileExt) {
            fileExt = fileExt.ext;
        }
        else {
            const ext = path.extname(file.name).split('.');
            fileExt = ext[ext.length - 1];
        }

        const checksum = await this._checkSum(file.path);
        const fileSize = fse.statSync(file.path).size;
        return { fileExt, checksum, fileSize };
    }
github apache / cordova-common / src / ConfigChanges / ConfigFile.js View on Github external
function isBinaryPlist (filename) {
    return readChunk.sync(filename, 0, 6).toString() === 'bplist';
}
github CFETeam / weapp-demo-album / server / routes / album / handlers / upload.js View on Github external
.then(({ files }) => {
                if (!('image' in files)) {
                    result.msg = '参数错误';
                    return;
                }

                const imageFile = files.image[0];

                const buffer = readChunk.sync(imageFile.path, 0, 262);
                const resultType = fileType(buffer);
                if (!resultType || !['image/jpeg', 'image/png'].includes(resultType.mime)) {
                    result.msg = '仅jpg/png格式';
                    return;
                }

                const srcpath = imageFile.path
                const imgKey = `${Date.now()}-${shortid.generate()}.${resultType.ext}`
                const params = {
                    Bucket: config.cosFileBucket,
                    Region: config.cosRegion,
                    Key: imgKey,
                    Body: srcpath,
                    ContentLength: imageFile.size
                }
github motivast / motimize / src / web / middlewares / handlers / image.js View on Github external
function checkMimeType(path) {

  let supportedMimTypes = config.get("mime_types");

  let buffer = readChunk.sync(path, 0, 4100);
  let type = fileType(buffer);

  if (!supportedMimTypes.includes(type.mime)) {
    throw boom.badRequest(
      `Uploaded image has unsupported mime type "${type.mime}". Supported mime types are "${supportedMimTypes.join('","')}".`
    );
  }

  return;
}
github lehoangduc / face-recognition-api / api / plugins / finder.js View on Github external
validateImage(path) {
    let buffer = readChunk.sync(path, 0, 12);
    let type = imageType(buffer);

    return new Promise((resolve, reject) => {
      if (this.validExtensions.indexOf(type.ext) === -1) {
        return reject(new Error(this.errors.url_image_invalid));
      }

      resolve(type.ext);
    });
  }

read-chunk

Read a chunk from a file

MIT
Latest version published 29 days ago

Package Health Score

80 / 100
Full package analysis

Popular read-chunk functions