Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derhuerst/files-sync-stream
Sync files over any transport.
https://github.com/derhuerst/files-sync-stream
files p2p sync webrtc
Last synced: 22 days ago
JSON representation
Sync files over any transport.
- Host: GitHub
- URL: https://github.com/derhuerst/files-sync-stream
- Owner: derhuerst
- License: isc
- Created: 2017-06-14T14:41:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-12-08T05:10:26.000Z (about 4 years ago)
- Last Synced: 2024-12-31T10:55:38.033Z (30 days ago)
- Topics: files, p2p, sync, webrtc
- Language: JavaScript
- Homepage: https://github.com/derhuerst/files-sync-stream
- Size: 28.3 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# files-sync-stream
**Sync files (or any blobs of data) between two peers, in both directions, over any transport.** Originally made for [avion](https://github.com/derhuerst/avion).
[![npm version](https://img.shields.io/npm/v/files-sync-stream.svg)](https://www.npmjs.com/package/files-sync-stream)
[![build status](https://img.shields.io/travis/derhuerst/files-sync-stream.svg)](https://travis-ci.org/derhuerst/files-sync-stream)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/files-sync-stream.svg)
[![chat on gitter](https://badges.gitter.im/derhuerst.svg)](https://gitter.im/derhuerst)- `files-sync-stream` is transport-agnostic. You need to pass two channels: one for sending [signaling](https://en.wikipedia.org/wiki/Signaling_(telecommunications)) data and one for sending chunks of data.
- You decide where and how to store the files. `files-sync-stream` accepts a generic file read function and emits `data` events when receiving data.Tings still to be implemented:
- A basic algorithm to determine the size of the next chunk to be transferred. Should be based on the time to transfer the last chunk.
- Handling of connection loss, including continuing the sync. This needs a basic have/want logic.## Installing
```shell
npm install files-sync-stream
```## Usage
This assumes the `dataTransport` and `signalingTransport` streams are connected the other peer somehow. You would do this for both peers.
```js
const createEndpoint = require('files-sync-stream')// 1st peer
const leader = createEndpoint(dataTransport, signalingTransport, true)
leader.on('file', (file) => { // handle incoming file
file.on('start', () => {
console.log('leader started receiving', file.id)
})
file.on('data', (chunk) => {
console.log('leader received', file.bytesTransferred, chunk.toString('hex'))
})
file.on('end', () => {
console.log('leader finished receiving', file.id)
})
})
leader.on('done', () => console.log('leader is done'))
``````js
// 2nd peerconst follower = endpoint(dataTransport, signalingTransport)
follower.on('file', (file) => {
// handle incoming file…
})
```Use `endpoint.add(read, metadata)` to transfer a file:
```js
const fromBuffer = require('files-sync-stream/from-buffer')const data = Buffer.from('aef18a02dd912638', 'hex')
follower.add(fromBuffer(data), {name: 'file.bin'})
```## Contributing
If you have a question or have difficulties using `files-sync-stream`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to [the issues page](https://github.com/derhuerst/files-sync-stream/issues).