How to use buffer-from - 9 common examples

To help you get started, we’ve selected a few buffer-from 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 pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-leveldb-core / src / index.js View on Github external
if (err) {
          return callback(err);
        }
        // do not try to store empty attachments
        if (data.length === 0) {
          return callback(err);
        }
        if (!isNewAttachment) {
          // small optimization - don't bother writing it again
          return callback(err);
        }
        txn.batch([{
          type: 'put',
          prefix: stores.binaryStore,
          key: digest,
          value: bufferFrom(data, 'binary')
        }]);
        callback();
      });
    }
github TooTallNate / node-data-uri-to-buffer / src / index.ts View on Github external
typeFull += `;${  meta[i]}`;
			if (meta[i].indexOf('charset=') === 0) {
				charset = meta[i].substring(8);
			}
		}
	}
	// defaults to US-ASCII only if type is not provided
	if (!meta[0] && !charset.length) {
		typeFull += ';charset=US-ASCII';
		charset = 'US-ASCII';
	}

	// get the encoded data portion and decode URI-encoded chars
	const encoding = base64 ? 'base64' : 'ascii';
	const data = unescape(uri.substring(firstComma + 1));
	const buffer = bufferFrom(data, encoding) as dataUriToBuffer.MimeBuffer;

	// set `.type` and `.typeFull` properties to MIME type
	buffer.type = type;
	buffer.typeFull = typeFull;

	// set the `.charset` property
	buffer.charset = charset;

	return buffer;
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-binary-utils / src / typedBuffer.js View on Github external
function typedBuffer(binString, buffType, type) {
  // buffType is either 'binary' or 'base64'
  var buff = bufferFrom(binString, buffType);
  buff.type = type; // non-standard, but used for consistency with the browser
  return buff;
}
github sfast / zeronode / src / sockets / envelope.js View on Github external
static dataToBuffer (data) {
    try {
      return BufferFrom(JSON.stringify({ data }))
    } catch (err) {
      console.error(err)
    }
  }
github tus / tus-js-client / lib / node / base64.js View on Github external
export function encode(data) {
  return bufferFrom(String(data)).toString("base64");
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-ajax / src / createBlobOrBufferFromParts.js View on Github external
return Buffer.concat(parts.map(function (part) {
    return bufferFrom(part, 'binary');
  }));
}
github mgcrea / node-xlsx / src / index.js View on Github external
export const build = (worksheets, options = {}) => {
  const defaults = {
    bookType: 'xlsx',
    bookSST: false,
    type: 'binary'
  };
  const workBook = new Workbook();
  worksheets.forEach((worksheet) => {
    const sheetName = worksheet.name || 'Sheet';
    const sheetOptions = worksheet.options || {};
    const sheetData = buildSheetFromMatrix(worksheet.data || [], {...options, ...sheetOptions});
    workBook.SheetNames.push(sheetName);
    workBook.Sheets[sheetName] = sheetData;
  });
  const excelData = XLSX.write(workBook, Object.assign({}, defaults, options));
  return excelData instanceof Buffer ? excelData : bufferFrom(excelData, 'binary');
};
github pouchdb / pouchdb / packages / node_modules / pouchdb-binary-utils / src / base64.js View on Github external
function thisBtoa(str) {
  return bufferFrom(str, 'binary').toString('base64');
}

buffer-from

A [ponyfill](https://ponyfill.com) for `Buffer.from`, uses native implementation if available.

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis

Popular buffer-from functions