
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
@ryanaltair/socket.io-stream
Advanced tools
Upload file as stream with socket.io, fork from @Akumzy/socket.io-stream
socket.io based file stream
This package has three components
Only works in Nodejs environment like in ElectronJs.
Web is for browsers based app the component uses FileReader api to read file blob.
This component handlers all the request from both Web
and Client
//Client
import { Client } from '@ryanaltair/socket.io-stream'
const client = new Client(socket, {
filepath: '/path/to/file/music.mp3',
data: {
//you pass your own data here
name: 'music.mp3'
}
})
client
.upload('file-upload', data => {
console.log({ data })
})
.on('progress', c => {
console.log(c) //{total,size}
})
.on('done', data => {
console.log(data)
})
.on('pause', () => {
console.log('pause')
})
.on('cancel', () => {
console.log('canceled')
})
//Web
function onChange(inputElement) {
let file = inputElement.files[0]
const client = new Web(socket, {
file: file,
data: {
name: file.name
}
})
client
.upload('file-upload', data => {
console.log({ data })
})
.on('progress', c => {
console.log(c) //{total,size}
})
.on('done', data => {
console.log(data)
})
.on('pause', () => {
console.log('pause')
})
.on('cancel', () => {
console.log('canceled')
})
}
//Server
import { Server } from '@ryanaltair/socket.io-stream'
import { appendFileSync } from 'fs'
const io = require('socket.io')(8090)
io.on('connection', socket => {
const server = new Server(socket)
server.on('file-upload', async ({ stream, data, ready }, ack) => {
try {
await someTask()
ready()
stream.subscribe({
next({ buffer, flag }) {
appendFileSync(data.name, buffer, {
encoding: 'binary',
flag
})
},
complete() {
ack(null, [1, 2, 3])
},
error(err) {
ack(err)
console.error(err)
}
})
} catch (err) {
console.error(err)
}
})
})
FAQs
Upload file as stream with socket.io, fork from @Akumzy/socket.io-stream
The npm package @ryanaltair/socket.io-stream receives a total of 6 weekly downloads. As such, @ryanaltair/socket.io-stream popularity was classified as not popular.
We found that @ryanaltair/socket.io-stream 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.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.