Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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)
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;
`;
}
// 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>
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/') &&
!mimeType.startsWith('image/') &&
!mimeType.startsWith('video/') &&
!mimeType.endsWith('/json')
) {
res.header('Content-disposition', `attachment; filename="${path.basename(FILE_OR_FOLDER_PATH)}"`);
}
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}`,
};
},
});
public isBinary(): Promise {
return isBinaryFile(this.realPath);
}
}
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')
}
utils.isBinary = async function(p) {
if (forceBinaryTypes.includes(ext(p))) {
return true;
}
return isbinaryfile.isBinaryFile(p);
};