Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
github.com/lqr471814/websocket-ftp
A simple FTP protocol with client and server implemented in TypeScript and Golang.
const buffer: Uint8Array = (new TextEncode()).encode("Testing Text")
new Transfer(
"ws://example.server.com/filetransfer",
[
{
Name: "Test File",
Size: buffer.length,
Type: "application/octet-stream",
data: buffer
},
],
{
onstart: () => {
console.log("Transfer has started.")
},
onprogress: (r, t) => console.log(`Sent ${r} / ${t} bytes`),
onsuccess: () =>
console.log("Success!"),
onclose: () =>
console.log("Closed WS connection"),
},
)
The client can also use a stream for the data
attribute,
this can be a nodeJS fs.ReadStream
constructed from fs.createReadStream(path)
or a the web ReadableStream
from calling File.stream()
Keep in mind, you will need to wrap each with either
the NodeFileStream
or BrowserFileStream
class.
type Hooks struct{}
func (h Hooks) OnTransferRequest(t *Transfer) chan bool {
log.Println("Got requests", t.Data.Files)
c := make(chan bool, 1)
c <- true
return c
}
func (h Hooks) OnTransferUpdate(t *Transfer) {
log.Println(
"Progress",
t.State.Received,
"/",
t.Data.Files[t.State.CurrentFile].Size,
)
}
func (h Hooks) OnTransferComplete(t *Transfer, f File) {
log.Println(f.Name, "has been received")
}
func (h Hooks) OnAllTransfersComplete(t *Transfer) {
log.Println("Transfer", t.ID, "has completed")
}
server := NewServer(ServerConfig{
Handlers: Hooks{},
})
server.Serve()
FAQs
Unknown package
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
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.