云盘
志元云盘
备份云盘
Home
/
志元云盘
/
webdav
/
sync
/
go
/
peerguard
/
fileshare
File
OriginalPic
Thumbnails
CopyAllDownloadUrl
EditTime
Size
common.go
2024-09-26 17:32:03
1.53 KB
downloader.go
2024-09-26 17:32:28
3.81 KB
filemanager.go
2024-09-26 17:32:59
5.44 KB
README.md
2024-09-26 16:51:09
1.1 KB
# fileshare A p2p file sharing library ### Example #### download ```go downloader := &fileshare.Downloader{ Server: "wss://synf.in/pg", ListenUDPPort: 29999, } read := func(fh *fileshare.FileHandle) error { // handshake (can set the offset to facilitate breakpoint resuming) if err := fh.Handshake(0, nil); err != nil { return err } reader, fileSize, err := fh.File() if err != nil { return err } f, err := os.Create(fh.Filename) if err != nil { return err } if err = io.Copy(io.MultiWriter(f, sum), reader); err != nil { return err } peerSum, err := fh.Sha256() // file checksum from peer if err != nil { return err } if !bytes.Equal(sum.Sum(nil), peerSum) { // assert that local and remote are consistent return errors.New("transfer error") } return nil } ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() err := downloader.Request(ctx, "pg://DJX2csRurJ3DvKeh63JebVHFDqVhnFjckdVhToAAiPYf/0/my-show.pptx", read) if err != nil { panic(err) } ```
2025-08-29 16:35:50 Friday 216.73.216.167 Runningtime:0.011s Mem:1.48 MB