How to use the msgpack5 function in msgpack5

To help you get started, we’ve selected a few msgpack5 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 ra-gg / Delir / packages / delir / src / domain / Editor / operations.ts View on Github external
async (
    context,
    { path, silent = false, keepPath = false }: { path: string; silent?: boolean; keepPath?: boolean },
  ) => {
    const project = context.getStore(EditorStore).getState().project
    if (!project) return

    await fs.writeFile(path, (MsgPack().encode({
      project: Delir.Exporter.serializeProject(project),
    }) as any) as Buffer)

    let newPath: string | null = path
    if (keepPath) {
      newPath = context.getStore(EditorStore).getState().projectPath
    }

    context.executeOperation(setActiveProject, { project, path: newPath }) // update path

    !silent &&
      (await context.executeOperation(notify, {
        message: t(t.k.saved),
        title: '',
        level: 'info',
        timeout: 1000,
github ra-gg / Delir / packages / delir / src / domain / Editor / operations.ts View on Github external
export const importProjectPack = operation(async ({executeOperation}, { src, dist: distDir }: {src: string, dist: string}) => {
  const tmpDir = path.join(remote.app.getPath('temp'), `delirpp-import-${uuid.v4()}`)
  await fs.mkdirp(tmpDir)

  await new Promise(resolve => {
    fs.createReadStream(src)
      .pipe(unzipper.Extract({ path: tmpDir }))
      .once('close',resolve)
  })

  const msgpack = MsgPack()
  const packProjectPath = path.join(tmpDir, 'project.msgpack')
  const {project: rawProject, assets} = msgpack.decode(await fs.readFile(packProjectPath))
  const project = Delir.Exporter.deserializeProject(rawProject)

  // Restore asset paths
  await Promise.all(Object.entries(assets as ProjectPackAssetMap).map(async ([id, {fileName, tmpName}]) => {
    const asset = project.findAsset(id)!
    await fs.rename(path.join(tmpDir, tmpName), path.join(tmpDir, fileName))
    asset.patch({path: path.join(/* Target to finalized dir */distDir, fileName) })
  }))

  // Save project to .delir
  const packFileName = path.parse(src).name
  const tmpProjectPath = path.join(tmpDir, `${packFileName}.delir`)

  await fs.writeFile(tmpProjectPath, msgpack.encode({
github KSDaemon / wampy.js / src / serializers / MsgpackSerializer.js View on Github external
import msgpack5 from 'msgpack5';

const msgpack = msgpack5();

export class MsgpackSerializer {
    constructor () {
        this.protocol = 'msgpack';
        this.isBinary = true;
    }

    encode (data) {
        return msgpack.encode(data);
    }

    decode (data) {
        return msgpack.decode(new Uint8Array(data));
    }
}
github nickvdyck / webtty / src / WebTty.UI / store / actions.ts View on Github external
async function writeToTerminal(msg: TerminalResizeMessage | TerminalInputMessage | TerminalNewTabMessage) {
    const msgpack = msgpack5()
    if (!terminal) return

    const payload = msgpack.encode(msg.serialize())
    terminal.send(payload.slice())
}
github ra-gg / Delir / packages / delir / src / domain / Editor / operations.ts View on Github external
export const openProject = operation(async (context, { path }: { path: string }) => {
  const projectMpk = await fs.readFile(path)
  const projectJson = MsgPack().decode(projectMpk).project
  const project = Delir.Exporter.deserializeProject(projectJson)
  const migrated = migrateProject(Delir.ProjectMigrator.migrate(project))


  await context.executeOperation(setActiveProject, {
    project: migrated,
    path: path[0],
  })
})
github remotelib / remote-lib / packages / remote-instance / src / parser.js View on Github external
constructor(opts = {}) {
    /**
     * @type {Object}
     * @private
     */
    this[kParser] = opts.parser || msgPack5();
  }
github nickvdyck / webtty / src / WebTty.UI / store / actions.ts View on Github external
async (dispatch) => {
        if (terminal) return

        terminal = await dispatch(connectToRemoteTerminal())

        const dataSource = fromEmitter(terminal)

        dispatch(createNewTab())

        const msgpack = msgpack5()
        const decoder = new TextDecoder()

        for await (let message of dataSource) {
            if (message === $terminated) break

            const properties = msgpack.decode(Buffer.from(message.data))
            const type: number = properties[0]

            switch (type) {
                case 0:
                case 1:
                case 3:
                    break

                case 2:
                    const id = properties[1]

msgpack5

A msgpack v5 implementation for node.js and the browser, with extension points

MIT
Latest version published 2 years ago

Package Health Score

58 / 100
Full package analysis

Popular msgpack5 functions