How to use the isbinaryfile.isBinaryFile function in isbinaryfile

To help you get started, we’ve selected a few isbinaryfile 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 electron-userland / electron-builder / packages / app-builder-lib / src / asar / unpackDetector.ts View on Github external
const pathInArchive = path.relative(rootForAppFilesWithoutAsar, getDestinationPath(file, fileSet))
    if (autoUnpackDirs.has(packageDirPathInArchive)) {
      // if package dir is unpacked, any file also unpacked
      addParents(pathInArchive, packageDirPathInArchive)
      continue
    }

    // https://github.com/electron-userland/electron-builder/issues/2679
    let shouldUnpack = false
    // ffprobe-static and ffmpeg-static are known packages to always unpack
    const moduleName = path.basename(packageDir)
    if (moduleName ===  "ffprobe-static" || moduleName === "ffmpeg-static" || isLibOrExe(file)) {
      shouldUnpack = true
    }
    else if (!file.includes(".", nextSlashIndex) && path.extname(file) === "") {
      shouldUnpack = await isBinaryFile(file)
    }

    if (!shouldUnpack) {
      continue
    }

    if (log.isDebugEnabled) {
      log.debug({file: pathInArchive, reason: "contains executable code"}, "not packed into asar archive")
    }

    addParents(pathInArchive, packageDirPathInArchive)
  }

  if (dirToCreate.size > 0) {
    await ensureDir(unpackedDest + path.sep + "node_modules")
    // child directories should be not created asynchronously - parent directories should be created first
github karma-runner / karma / lib / preprocessor.js View on Github external
return async function preprocess (file) {
    const buffer = await tryToRead(file.originalPath, log)
    const isBinary = await isBinaryFile(buffer, buffer.length)

    const preprocessorNames = Object.keys(config).reduce((ppNames, pattern) => {
      if (mm(file.originalPath, pattern, { dot: true })) {
        ppNames = _.union(ppNames, config[pattern])
      }
      return ppNames
    }, [])

    // Apply preprocessor priority.
    const preprocessors = preprocessorNames
      .map((name) => [name, preprocessorPriority[name] || 0])
      .sort((a, b) => b[1] - a[1])
      .map((duo) => duo[0])
      .reduce((preProcs, name) => {
        const p = instantiatePreprocessor(name)
github open-wc / open-wc / packages / es-dev-server / src / utils / utils.js View on Github external
if (isStream(ctx.body)) {
    // cache request path, see above
    // @ts-ignore
    if (ctx.body.path) {
      // @ts-ignore
      filePathsForRequests.set(ctx.request, ctx.body.path);
    }

    // a stream can only be read once, so after reading it assign
    // the string response to the body so that it can be accessed
    // again later
    try {
      const bodyBuffer = await getStream.buffer(ctx.body);
      const contentLength = Number(ctx.response.get('content-length'));

      if (await isBinaryFile(bodyBuffer, contentLength)) {
        ctx.body = bodyBuffer;
        throw new IsBinaryFileError();
      }

      const bodyString = bodyBuffer.toString();
      ctx.body = bodyString;
      return bodyString;
    } catch (error) {
      if (requestCanceled) {
        throw new RequestCancelledError();
      }
      throw error;
    }
  }

  return ctx.body;
github egodigital / ego-cli / src / commands / serve / index.ts View on Github external
 
`;
                                    }

                                    // files
                                    for (const F of FILES.sort((x, y) => {
                                        return compareValuesBy(x, y, i => {
                                            return toStringSafe(i.name)
                                                .toLowerCase()
                                                .trim();
                                        });
                                    })) {
                                        let mimeType = getMimeType(F.path);
                                        if ('application/octet-stream' === mimeType) {
                                            try {
                                                if (!(await isBinaryFile(F.path))) {
                                                    mimeType = 'text/plain';
                                                }
                                            } catch { }
                                        }

                                        content += `    
    <a href="/?p=${
                                            encodeURIComponent(
                                                currentDir + '/' + F.name
                                            )
                                            }"><i class="fa fa-arrow-circle-o-down mr-4 pr-3"></i></a>
github egodigital / ego-cli / src / commands / serve / index.ts View on Github external
content += ``;

                                const HTML = `${HEADER}${content}${FOOTER}`;

                                return res.status(200)
                                    .header('Content-type', 'text/html; charset=utf-8')
                                    .send(Buffer.from(HTML, 'utf8'));
                            }

                            // send file ...

                            let mimeType = getMimeType(FILE_OR_FOLDER_PATH);
                            if ('application/octet-stream' === mimeType) {
                                try {
                                    if (!(await isBinaryFile(FILE_OR_FOLDER_PATH))) {
                                        mimeType = 'text/plain';
                                    }
                                } catch { }
                            }

                            res.status(200)
                                .header('Content-type', mimeType);

                            if (
                                !mimeType.startsWith('text/') &amp;&amp;
                                !mimeType.startsWith('image/') &amp;&amp;
                                !mimeType.startsWith('video/') &amp;&amp;
                                !mimeType.endsWith('/json')
                            ) {
                                res.header('Content-disposition', `attachment; filename="${path.basename(FILE_OR_FOLDER_PATH)}"`);
                            }
github parcel-bundler / parcel / packages / optimizers / data-url / src / DataURLOptimizer.js View on Github external
async optimize({bundle, contents}) {
    let bufferContents = await blobToBuffer(contents);
    let hasBinaryContent = await isBinaryFile(bufferContents);

    // Follows the data url format referenced here:
    // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
    let mimeType = mime.getType(bundle.filePath) ?? '';
    let encoding = hasBinaryContent ? ';base64' : '';
    let content = encodeURIComponent(
      hasBinaryContent
        ? bufferContents.toString('base64')
        : bufferContents.toString(),
    );
    return {
      contents: `data:${mimeType}${encoding},${content}`,
    };
  },
});
github atomist / automation-client / lib / project / local / NodeFsLocalFile.ts View on Github external
public isBinary(): Promise {
        return isBinaryFile(this.realPath);
    }
}
github little-core-labs / pkg-packager / lib / packager.js View on Github external
steps.push((next) => {
        errback(isBinaryFile(pathspec), (err, result) => {
          if (err) { return next(err) }

          if (result) {
            target.binary = pathspec
            return next(null)
          }

          const pkgArgs = [pathspec, '--targets', target.platform.host]

          if (opts.config || target.config) {
            pkgArgs.push('--config', opts.config || target.config)
          }

          if (opts.debug) {
            pkgArgs.push('--debug')
          }
github silverwind / droppy / server / utils.js View on Github external
utils.isBinary = async function(p) {
  if (forceBinaryTypes.includes(ext(p))) {
    return true;
  }

  return isbinaryfile.isBinaryFile(p);
};

isbinaryfile

Detects if a file is binary in Node.js. Similar to Perl's -B.

MIT
Latest version published 3 months ago

Package Health Score

85 / 100
Full package analysis