How to use buffer-json - 6 common examples

To help you get started, we’ve selected a few buffer-json 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 dcloudio / uni-app / packages / vue-cli-plugin-uni / lib / cache-loader.js View on Github external
function write (key, data, callback) {
  const dirname = path.dirname(key)
  // template,缓存 mp template
  if (
    data.remainingRequest.indexOf('vue&type=template') !== -1 &&
    process.UNI_CACHE_TEMPLATES
  ) {
    data['mpTemplates'] = process.UNI_CACHE_TEMPLATES
    delete process.UNI_CACHE_TEMPLATES
  }

  const content = BJSON.stringify(data)

  if (directories.has(dirname)) {
    // for performance skip creating directory
    fs.writeFile(key, content, 'utf-8', callback)
  } else {
    mkdirp(dirname, (mkdirErr) => {
      if (mkdirErr) {
        callback(mkdirErr)
        return
      }

      directories.add(dirname)

      fs.writeFile(key, content, 'utf-8', callback)
    })
  }
github jprichardson / electron-ipc-stream / src / main.js View on Github external
MainIPCStream.prototype._write = function (data, enc, next) {
  if (typeof data === 'string') {
    data = JSON.stringify(data)
  }
  if (Buffer.isBuffer(data)) {
    data = JSON.stringify(data, null, bufferJson.replacer)
  }
  if (!this.browserWindow) return console.warn('MainIPCStream: trying to write when no browserWindow is set.')
  this.browserWindow.webContents.send(this.channel, data)
  next()
}
github jprichardson / electron-ipc-stream / src / rend.js View on Github external
RendIPCStream.prototype._write = function (data, enc, next) {
  if (typeof data === 'string') {
    data = JSON.stringify(data)
  }
  if (Buffer.isBuffer(data)) {
    data = JSON.stringify(data, null, bufferJson.replacer)
  }

  ipcRenderer.send(this.channel, data)
  next()
}
github jprichardson / electron-ipc-stream / src / main.js View on Github external
const ipcCallback = (event, data) => {
    if (typeof data === 'string') {
      data = JSON.parse(data, bufferJson.reviver)
    }
    this.push(data)
  }
  ipcMain.on(this.channel, ipcCallback)
github jprichardson / electron-ipc-stream / src / rend.js View on Github external
const ipcCallback = (event, data) => {
    if (typeof data === 'string') {
      data = JSON.parse(data, bufferJson.reviver)
    }
    this.push(data)
  }
  ipcRenderer.on(this.channel, ipcCallback)
github dcloudio / uni-app / packages / vue-cli-plugin-uni / lib / cache-loader.js View on Github external
fs.readFile(key, 'utf-8', (err, content) => {
    if (err) {
      callback(err)
      return
    }

    try {
      const data = BJSON.parse(content)
      const mpTemplates = data['mpTemplates']
      if (mpTemplates) {
        Object.keys(mpTemplates).forEach(name => {
          fs.writeFileSync(name, mpTemplates[name], 'utf-8')
        })
      }
      callback(null, data)
    } catch (e) {
      callback(e)
    }
  })
}

buffer-json

JSON.stringify & JSON.parse which can encode/decode buffers.

MIT
Latest version published 6 years ago

Package Health Score

62 / 100
Full package analysis