How to use the fs-jetpack.readAsync function in fs-jetpack

To help you get started, we’ve selected a few fs-jetpack 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 ashmind / SharpLab / source / WebApp / build.ts View on Github external
async function getIconDataUrl() {
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    const faviconSvg = (await jetpack.readAsync(paths.from.icon))!;
    // http://codepen.io/jakob-e/pen/doMoML
    return faviconSvg
        .replace(/"/g, '\'')
        .replace(/%/g, '%25')
        .replace(/#/g, '%23')
        .replace(/{/g, '%7B')
        .replace(/}/g, '%7D')
        .replace(//g, '%3E')
        .replace(/\s+/g, ' ');
}
github WeebDev / lolisafe / src / api / routes / files / uploadPOST.js View on Github external
Seems we finally got the last part of a chunk upload
			*/
			const uploadsDir = path.join(__dirname, '..', '..', '..', '..', process.env.UPLOAD_FOLDER);
			const chunkedFileDir = path.join(__dirname, '..', '..', '..', '..', process.env.UPLOAD_FOLDER, 'chunks', file.body.uuid);
			const chunkFiles = await jetpack.findAsync(chunkedFileDir, { matching: '*' });
			const originalname = Util.getFilenameFromPath(chunkFiles[0].substring(0, chunkFiles[0].lastIndexOf('.')));

			const tempFile = {
				filename: Util.getUniqueFilename(originalname),
				originalname,
				size: file.body.totalfilesize
			};

			for (const chunkFile of chunkFiles) {
				try {
					const data = await jetpack.readAsync(chunkFile, 'buffer'); // eslint-disable-line no-await-in-loop
					await jetpack.appendAsync(path.join(uploadsDir, tempFile.filename), data); // eslint-disable-line no-await-in-loop
				} catch (error) {
					log.error(error);
				}
			}

			try {
				await jetpack.removeAsync(chunkedFileDir);
			} catch (error) {
				log.error(error);
			}

			upload = tempFile;
		}

		/*
github beakerbrowser / beaker / app / background-process / protocols / beaker.js View on Github external
async function serveICO (path, size = 16) {
    // read the file
    const data = await jetpack.readAsync(path, 'buffer')

    // parse the ICO to get the 16x16
    const images = await ICO.parse(data, 'image/png')
    let image = images[0]
    for (let i = 1; i < images.length; i++) {
      if (Math.abs(images[i].width - size) < Math.abs(image.width - size)) {
        image = images[i]
      }
    }

    // serve
    cb(200, 'OK', 'image/png', () => Buffer.from(image.buffer))
  }
github ashmind / SharpLab / source / WebApp / build.ts View on Github external
const htmlPromises = htmlPaths.map(async htmlPath => {
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        const template = (await jetpack.readAsync(htmlPath))!;
        const minified = htmlMinifier.minify(template, { collapseWhitespace: true });
        return ``;
    });
    return (await Promise.all(htmlPromises)).join('\r\n');
github ashmind / mirrorsharp / WebAssets / build.ts View on Github external
const files = task('files', async () => {
    await jetpack.copyAsync('./README.md', 'dist/README.md', { overwrite: true });
    const packageJson = JSON.parse((await jetpack.readAsync('./package.json'))!);
    // cannot be specified in current package.json due to https://github.com/TypeStrong/ts-node/issues/935
    // which is fine, from perspective of the project itself it's TypeScript, so type=module is irrelevant
    // only the output (dist) is JS modules
    packageJson.type = 'module';
    await jetpack.writeAsync('dist/package.json', JSON.stringify(packageJson, null, 4));
}, { watch: ['./README.md', './package.json'] });
github WeebDev / lolisafe / src / api / utils / Util.js View on Github external
static async getFileHash(filename) {
		const file = await jetpack.readAsync(path.join(__dirname, '..', '..', '..', process.env.UPLOAD_FOLDER, filename), 'buffer');
		if (!file) {
			log.error(`There was an error reading the file < ${filename} > for hashing`);
			return null;
		}

		const hash = crypto.createHash('md5');
		hash.update(file, 'utf8');
		return hash.digest('hex');
	}
github beakerbrowser / beaker / app / bg / browser.js View on Github external
export async function uploadFavicon () {
  let favicon = dialog.showOpenDialog({
    title: 'Upload Favicon...',
    defaultPath: app.getPath('home'),
    buttonLabel: 'Upload Favicon',
    filters: [
      { name: 'Images', extensions: ['png', 'ico', 'jpg'] }
    ],
    properties: ['openFile']
  })

  if (!favicon) return

  let faviconBuffer = await jetpack.readAsync(favicon[0], 'buffer')
  let extension = path.extname(favicon[0])

  if (extension === '.png') {
    return toIco(faviconBuffer, {resize: true})
  }
  if (extension === '.jpg') {
    let imageToPng = nativeImage.createFromBuffer(faviconBuffer).toPNG()
    return toIco(imageToPng, {resize: true})
  }
  if (extension === '.ico' && ICO.isICO(faviconBuffer)) {
    return faviconBuffer
  }
}
github v12 / node-vk-api / src / token-storage.js View on Github external
getToken () {
    return fs.readAsync(this.storageFile)
  }
github beakerbrowser / beaker / app / background-process / analytics.js View on Github external
async function readPingData () {
  var data = await jetpack.readAsync(path.join(app.getPath('userData'), ANALYTICS_DATA_FILE), 'json')
  return data || {lastPingTime: 0, id: crypto.randomBytes(32).toString('hex')}
}