0.3.7-ts • Published 5 years ago

socket.io-file-stream v0.3.7-ts

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

socket.io-file-stream

socket.io based file stream

This package has three components

  • Client:

    Only works on node environment bacause it's uses node fs.creatReadStream which makes sense for electron applications.

  • Web:

    Web is for browsers baseds app the component uses FileReader api to read file blob.

  • Server:

    This component handlers all the request from both Web and Client

//Client
import { Client } from 'socket.io-file-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 'socket.io-file-stream'
io.on('connection', socket => {
	console.log('hurrey')
	const server = new Server(socket)

	server.on('file-upload', ({ stream, data: { data } }, done) => {
		console.log('stream')
		const writable = createWriteStream(data.name, {
			autoClose: true
		})
		stream.pipe(writable)
		writable.on('close', () => {
			//make sure to call this function
			//only when you're done, you can
			//pass a value to it which will be
			//sent back to client as well
			done('good')
		})
	})
})

Please check the example folder for clue on how to use package until I'm able to document this package well

0.4.0-ts

5 years ago

0.3.9-ts

5 years ago

0.3.8-ts

5 years ago

0.3.7-ts

5 years ago

0.3.6-ts

5 years ago

0.3.5-ts

5 years ago

0.3.4-ts

5 years ago

0.3.3-ts

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago