Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
arraybuffer-mime
Advanced tools
Prepends fixed length byte array to indicate mime type of the ArrayBuffer.
Prepends fixed length byte array to indicate mime type of the ArrayBuffer.
npm install arraybuffer-mime
Basic example:
const {
arrayBufferWithMime,
arrayBufferMimeDecouple
} = require('arraybuffer-mime')
// "some image"
const uint8 = new Uint8Array(1)
uint8[0] = 1
const ab = uint8.buffer
const mime = 'image/png'
const abWithMime = arrayBufferWithMime(ab, mime)
const {mime, arrayBuffer} = arrayBufferMimeDecouple(abWithMime)
console.log(mime) // "image/png"
console.log(arrayBuffer) // ArrayBuffer
Example demonstrating sending a binary file over Websockets:
const {
arrayBufferWithMime,
arrayBufferMimeDecouple
} = require('arraybuffer-mime')
const ws = new WebSocket(`ws://localhost:8080/`)
ws.binaryType = 'arraybuffer'
const fileInput = document.querySelector('input[type="file"]')
const file = fileInput.files[0]
const reader = new FileReader()
const readFile = (event) => {
const arrayBuffer = reader.result
const mime = file.type
const abWithMime = arrayBufferWithMime(arrayBuffer, mime)
ws.send(abWithMime)
}
reader.addEventListener('load', readFile)
reader.readAsArrayBuffer(file)
ws.on('message', (event) => {
const abWithMime = event.data
const {mime, arrayBuffer} = arrayBufferMimeDecouple(abWithMime)
const blob = new Blob([arrayBuffer], {type: mime})
const url = window.URL.createObjectURL(blob)
console.log(url)
})
npm test
MIT
FAQs
Prepends byte array to indicate mime type of the ArrayBuffer.
The npm package arraybuffer-mime receives a total of 12 weekly downloads. As such, arraybuffer-mime popularity was classified as not popular.
We found that arraybuffer-mime demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.