Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
处理 JavaScript 二进制的数据,支持 Blob、ArrayBuffer、File、Base64 之间的互转
ArrayBuffer
转换为 Blob
Blob
转换为 ArrayBuffer
ArrayBuffer
转换为 Base64 编码字符串ArrayBuffer
Blob
转换为 Base64 编码字符串Blob
你可以通过 npm 或 yarn 或 pnpm 安装 binaryX
:
npm install binaryX
# 或者
yarn add binaryX
# 或者
pnpm add binaryX
首先,导入你需要的函数:
import {
arrayBufferToBlob,
blobToArrayBuffer,
arrayBufferToBase64,
base64ToArrayBuffer,
blobToBase64,
base64ToBlob,
blobToFile,
fileToBlob,
} from 'binaryX'
然后,使用这些函数来处理你的二进制数据:
// 创建 ArrayBuffer
const buffer = new ArrayBuffer(16)
// ArrayBuffer 转换为 Blob
const blob = arrayBufferToBlob(buffer)
// Blob 转换为 ArrayBuffer
;(async () => {
const arrayBuffer = await blobToArrayBuffer(blob)
console.log(arrayBuffer)
})()
// ArrayBuffer 转换为 Base64
const base64String = arrayBufferToBase64(buffer)
console.log(base64String)
// Base64 转换为 ArrayBuffer
const decodedArrayBuffer = base64ToArrayBuffer(base64String)
console.log(decodedArrayBuffer)
// Blob 转换为 Base64
;(async () => {
const base64String = await blobToBase64(blob)
console.log(base64String)
})()
// Base64 转换为 Blob
const newBlob = base64ToBlob(base64String, 'image/png')
console.log(newBlob)
// Blob 转换为 File
const file = blobToFile(blob, 'example.txt');
console.log(file);
// File 转换为 Blob
const fileBlob = fileToBlob(file);
console.log(fileBlob);
如果你有任何建议或想要贡献代码,请提交 Pull Request 或创建 Issue。
FAQs
处理 JavaScript 二进制的数据,支持 Blob、ArrayBuffer、File、Base64 之间的互转
The npm package binaryx receives a total of 1 weekly downloads. As such, binaryx popularity was classified as not popular.
We found that binaryx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.