How to use the file-box.FileBox.fromFile function in file-box

To help you get started, we’ve selected a few file-box 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 wechaty / wechaty / examples / self-testing-bot.ts View on Github external
/**
       * 1. reply 'dong'
       */
      log.info('Bot', 'REPLY: dong')
      await msg.say('dong')

      const joinWechaty =  `Join Wechaty Developers' Community\n\n` +
                            `Wechaty is used in many ChatBot projects by hundreds of developers.\n\n` +
                            `If you want to talk with other developers, just scan the following QR Code in WeChat with secret code: wechaty,\n\n` +
                            `you can join our Wechaty Developers' Home at once`
      await msg.say(joinWechaty)

      /**
       * 2. reply qrcode image
       */
      const fileBox = FileBox.fromFile(BOT_QR_CODE_IMAGE_FILE)
      // const fileBox = FileBox.packStream(
      //   fs.createReadStream(BOT_QR_CODE_IMAGE_FILE),
      //   BOT_QR_CODE_IMAGE_FILE,
      // )

      log.info('Bot', 'REPLY: %s', fileBox)
      await msg.say(fileBox)

      /**
       * 3. reply 'scan now!'
       */
      await msg.say('Scan now, because other Wechaty developers want to talk with you too!\n\n(secret code: wechaty)')

    }
  } catch (e) {
    log.error('Bot', 'on(message) exception: %s' , e)
github wechaty / wechaty-getting-started / examples / advanced / self-testing-bot.js View on Github external
/**
       * 1. reply 'dong'
       */
      log.info('Bot', 'REPLY: dong')
      await msg.say('dong')

      const joinWechaty =  `Join Wechaty Developers' Community\n\n` +
                            `Wechaty is used in many ChatBot projects by hundreds of developers.\n\n` +
                            `If you want to talk with other developers, just scan the following QR Code in WeChat with secret code: wechaty,\n\n` +
                            `you can join our Wechaty Developers' Home at once`
      await msg.say(joinWechaty)

      /**
       * 2. reply qrcode image
       */
      const fileBox = FileBox.fromFile(BOT_QR_CODE_IMAGE_FILE)
      // const fileBox = FileBox.packStream(
      //   fs.createReadStream(BOT_QR_CODE_IMAGE_FILE),
      //   BOT_QR_CODE_IMAGE_FILE,
      // )

      log.info('Bot', 'REPLY: %s', fileBox)
      await msg.say(fileBox)

      /**
       * 3. reply 'scan now!'
       */
      await msg.say('Scan now, because other Wechaty developers want to talk with you too!\n\n(secret code: wechaty)')

    }
  } catch (e) {
    log.error('Bot', 'on(message) exception: %s' , e)
github huan / file-box / tests / fixtures / smoke-testing.ts View on Github external
import Default, {
  FileBox,
  VERSION,
}             from 'file-box'

if (VERSION as any === '0.0.0') {
  throw new Error('version not set right before publish!')
}

if (Default !== FileBox) {
  throw new Error('default export does not match the exported module!')
}

const box = FileBox.fromFile(__filename)
console.log(`FileBox v${box.version()} smoke testing passed!`)
github BingKui / WeChatRobot / tools / assetTools.js View on Github external
const randomFile = (foolder) => {
    const path = `${process.cwd()}/assets/${foolder}`;
    const pathData = readDirData(path);
    let result = '暂时没有相关资源!';
    if (pathData.length > 0) {
        const filename = pathData[randomNum(0, pathData.length - 1)];
        result = FileBox.fromFile(`${path}/${filename}`);
    }
    console.log('获取到的文件为:', result);
    return result;
}
github BingKui / WeChatRobot / tools / assetTools.js View on Github external
const avatarImg = () => {
    const num = dayjs().day();
    return FileBox.fromFile(`${process.cwd()}/assets/avatar/${num}.jpg`, 'avatar');
}

file-box

Pack a File into Box for easy move/transfer between servers no matter of where it is.(local path, remote url, or cloud storage)

Apache-2.0
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis