.then(_ => promisify(fs.readFile)(OUT_FILE))
export function truncate(path: string, len: number): Promise<void> { return promisify(fs.truncate)(path, len); }
import SteamCommunity from 'steamcommunity'; import { promisify } from 'util'; import debug from 'debug'; import config from 'config'; const log = debug('TF2Pickup:utils:steam-community'); const steamCommunity = new SteamCommunity(); const login = promisify(steamCommunity.login.bind(steamCommunity)); const username = config.get<string | null>('services.steam.username'); const password = config.get<string | null>('services.steam.password'); export async function setupSteam() { if (password === null || username === null) { return; } try { await login({ accountName: username, password, }); log('Successfully logged into steam'); } catch (error) { log('Error while logging into steam', { error }); } } export default steamCommunity;
export function lstat(path: string): Promise<fs.Stats> { return promisify(fs.lstat)(path); }
export function unlink(path: string): Promise<void> { return promisify(fs.unlink)(path); }
import getRes from 'get-res'; import logSymbols from 'log-symbols'; import mem from 'mem'; import makeDir from 'make-dir'; import captureWebsite from 'capture-website'; import viewportList from 'viewport-list'; import filenamify from 'filenamify'; import filenamifyUrl from 'filenamify-url'; import template from 'lodash.template'; import plur from 'plur'; import unusedFilename from 'unused-filename'; // TODO: Move this to `type-fest` type Mutable<ObjectType> = {-readonly [KeyType in keyof ObjectType]: ObjectType[KeyType]}; const writeFile = promisify(fs.writeFile); export interface Options { readonly delay?: number; readonly timeout?: number; readonly crop?: boolean; readonly css?: string; readonly script?: string; readonly cookies?: readonly (string | {[key: string]: string})[]; readonly filename?: string; readonly incrementalName?: boolean; readonly selector?: string; readonly hide?: readonly string[]; readonly username?: string; readonly password?: string; readonly scale?: number;
export function exists(path: string): Promise<boolean> { return promisify(fs.exists)(path); }
'use strict'; import { conn, Product, User } from '../models'; import { promisify } from 'util'; const readFile = promisify(require('fs').readFile); conn.once('open', () => { main().then(() => conn.close()); }); async function main() { try { let users = JSON.parse(await readFile('./initial_data/userMocks.json', 'utf8')); console.log(`Read ${users.length} users.`); for (let userData of users) { const newUser = new User(userData); let user = await newUser.save(); console.log(`Saved "${user.name}" (${user._id})`); } console.log('Users loaded!'); let products = JSON.parse(await readFile('./initial_data/productMocks.json', 'utf8')); console.log(`Read ${products.length} products.`); for (let productData of products) { let newProduct = new Product(productData); let product = await newProduct.save(); console.log(`Saved "${product.name}" (${product._id})`); } console.log('Products loaded!');
// tslint:disable:no-console import * as fs from "fs"; import * as path from "path"; import * as ts from "typescript"; import { promisify } from "util"; import { assert } from "node-opcua-assert"; import { checkDebugFlag, make_debugLog } from "node-opcua-debug"; import { ConstructorFunc } from "node-opcua-factory"; import { get_class_tscript_filename, produce_tscript_code } from "./factory_code_generator"; const debugLog = make_debugLog(__filename); const doDebug = checkDebugFlag(__filename); const fileExists = promisify(fs.exists); const mkdir = promisify(fs.mkdir); /** * @module opcua.miscellaneous * @class Factory * @static */ function compileTscriptCode(typescriptFilename: string): string { const content = fs.readFileSync(typescriptFilename, "ascii"); const compilerOptions = { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2016,
import { writeFile, writeFileSync } from 'fs'; import { extname } from 'path'; import { promisify } from 'util'; import { Image } from '../Image'; import { encode, ImageFormat, IEncodeOptionsPng, IEncodeOptionsJpeg } from './encode'; const writeFilePromise = promisify(writeFile); /** * Write an image to the disk. * The file format is determined automatically from the file's extension. * If the extension is not supported, an error will be thrown. */ export async function write(path: string, image: Image): Promise<void>; /** * Write an image to the disk as PNG. * When the `png` format is specified, the file's extension doesn't matter. */ export async function write( path: string, image: Image, options: IEncodeOptionsPng ): Promise<void>; /**