How to use the file-type.fromBuffer function in file-type

To help you get started, we’ve selected a few file-type 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 Grathium-Industries / labyrinth / src / main / services / storage.ts View on Github external
public addFavicon = async (url: string): Promise => {
    if (!this.favicons.get(url)) {
      const res = await requestURL(url);

      if (res.statusCode === 404) {
        throw new Error('404 favicon not found');
      }

      let data = Buffer.from(res.data, 'binary');

      const type = await fromBuffer(data);

      if (type && type.ext === 'ico') {
        data = Buffer.from(new Uint8Array(await convertIcoToPng(data)));
      }

      const str = `data:${(await fromBuffer(data)).ext};base64,${data.toString(
        'base64',
      )}`;

      this.insert({
        scope: 'favicons',
        item: {
          url,
          data: str,
        },
      });
github Grathium-Industries / labyrinth / src / main / services / storage.ts View on Github external
if (!this.favicons.get(url)) {
      const res = await requestURL(url);

      if (res.statusCode === 404) {
        throw new Error('404 favicon not found');
      }

      let data = Buffer.from(res.data, 'binary');

      const type = await fromBuffer(data);

      if (type && type.ext === 'ico') {
        data = Buffer.from(new Uint8Array(await convertIcoToPng(data)));
      }

      const str = `data:${(await fromBuffer(data)).ext};base64,${data.toString(
        'base64',
      )}`;

      this.insert({
        scope: 'favicons',
        item: {
          url,
          data: str,
        },
      });

      this.favicons.set(url, str);

      return str;
    } else {
      return this.favicons.get(url);

file-type

Detect the file type of a Buffer/Uint8Array/ArrayBuffer

MIT
Latest version published 4 months ago

Package Health Score

90 / 100
Full package analysis