Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* target can have one of these forms:
* - /path/to/file
* - C:/path/to/file
* - file:///path/to/file
* - file:///C:/path/to/file
*
* That's why we need to parse it to an URL
* and then get the path string.
*/
const uri = getAsUri(target);
const filePath: string = uri ? asPathString(uri).replace('%20', ' ') : '';
const rawContent: Buffer = options && options.content ? Buffer.from(options.content) : await readFileAsBuffer(filePath);
const contentType = getContentTypeData(null as any, filePath, null, rawContent);
let content = '';
if (isTextMediaType(contentType.mediaType || '')) {
content = rawContent.toString(contentType.charset || undefined);
}
// Need to do some magic to create a fetch::end::*
return {
request: {} as any,
response: {
body: {
content,
rawContent,
rawResponse() {
/* istanbul ignore next */
return Promise.resolve(rawContent);
}
},
charset: contentType.charset || /* istanbul ignore next */ '',
'font/otf',
'font/sfnt',
'font/ttf',
'image/bmp',
'image/x-icon',
'x-shader/x-fragment',
'x-shader/x-vertex'
];
/*
* Check if the media type is one of the common
* ones for which it is known the response should
* be compressed.
*/
if (isTextMediaType(mediaType) ||
OTHER_COMMON_MEDIA_TYPES_THAT_SHOULD_BE_COMPRESSED.includes(mediaType)) {
return true;
}
return false;
};