transfer

package
v0.0.0-...-4b87c6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package transfer provides client and server for file transfer.

Package transfer provides client and server for file transfer.

Package transfer provides client and server for file transfer.

Package transfer provides client and server for file transfer.

Package transfer provides client and server for file transfer.

Package transfer provides client and server for file transfer.

Index

Constants

View Source
const (
	// BLOCK_SIZE is the size of each block to be transferred.
	BLOCK_SIZE = 512 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Addr string
	// contains filtered or unexported fields
}

Client is a file transfer client.

func NewClient

func NewClient(addr string) *Client

NewClient creates a new Client.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the server.

func (*Client) CloseSession

func (c *Client) CloseSession(sessionId SessionId) error

CloseSession closes a session on the server.

func (*Client) Dial

func (c *Client) Dial() error

Dial connects to the server.

func (*Client) Download

func (c *Client) Download(filename, saveFile string) error

Download downloads a file from the server.

func (*Client) DownloadAt

func (c *Client) DownloadAt(filename, saveFile string, blockId int) error

DownloadAt downloads a file from the server, starting from a specific block.

func (*Client) GetBlock

func (c *Client) GetBlock(sessionId SessionId, blockId int) ([]byte, error)

GetBlock gets a block of data from the server.

func (*Client) Open

func (c *Client) Open(filename string) (SessionId, error)

Open opens a file on the server and returns a session ID.

func (*Client) Read

func (c *Client) Read(sessionId SessionId, buf []byte) (int, error)

Read reads data from the server.

func (*Client) ReadAt

func (c *Client) ReadAt(sessionId SessionId, offset int64, size int) ([]byte, error)

ReadAt reads data from the server at a specific offset.

func (*Client) Stat

func (c *Client) Stat(filename string) (*StatResponse, error)

Stat returns file information from the server.

type FileRequest

type FileRequest struct {
	Filename string
}

FileRequest is a request with a filename.

type GetRequest

type GetRequest struct {
	Id      SessionId
	BlockId int
}

GetRequest is a request to get a block of data.

type GetResponse

type GetResponse struct {
	BlockId int
	Size    int64
	Data    []byte
}

GetResponse is a response containing a block of data.

type ReadCloser

type ReadCloser struct {
	// contains filtered or unexported fields
}

ReadCloser is a wrapper around the client to provide an io.ReadCloser interface.

func NewReadCloser

func NewReadCloser(client *Client, sessionId SessionId) *ReadCloser

NewReadCloser creates a new ReadCloser.

func (*ReadCloser) Close

func (r *ReadCloser) Close() error

Close closes the session.

func (*ReadCloser) Read

func (r *ReadCloser) Read(buf []byte) (int, error)

Read reads data from the stream.

func (*ReadCloser) SessionId

func (r *ReadCloser) SessionId() SessionId

SessionId returns the session ID.

type ReadRequest

type ReadRequest struct {
	Id     SessionId
	Offset int64
	Size   int
}

ReadRequest is a request to read data.

type ReadResponse

type ReadResponse struct {
	Size int
	Data []byte
	EOF  bool
}

ReadResponse is a response containing data read from a file.

type Request

type Request struct {
	Id SessionId
}

Request is a generic request with a session ID.

type Response

type Response struct {
	Id     SessionId
	Result bool
}

Response is a generic response.

type Rpc

type Rpc struct {
	// contains filtered or unexported fields
}

Rpc is the RPC service.

func (*Rpc) Close

func (r *Rpc) Close(req Request, res *Response) error

Close closes a session.

func (*Rpc) Open

func (r *Rpc) Open(req FileRequest, res *Response) error

Open opens a file and returns a session ID.

func (*Rpc) Read

func (r *Rpc) Read(req ReadRequest, res *ReadResponse) error

Read reads data from a file.

func (*Rpc) ReadAt

func (r *Rpc) ReadAt(req ReadRequest, res *ReadResponse) error

ReadAt reads data from a file at a specific offset.

func (*Rpc) Stat

func (r *Rpc) Stat(req FileRequest, res *StatResponse) error

Stat returns file information.

type Server

type Server struct {
	Addr          string
	ReadDirectory string
}

Server is a file transfer server.

func NewServer

func NewServer(addr, readDirectory string) *Server

NewServer creates a new Server.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe starts the server.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session manages file transfer sessions.

func (*Session) Add

func (s *Session) Add(file *os.File) SessionId

Add adds a file to the session and returns a new session ID.

func (*Session) Delete

func (s *Session) Delete(id SessionId)

Delete removes a session by its ID.

func (*Session) Get

func (s *Session) Get(id SessionId) *os.File

Get returns the file for a given session ID.

func (*Session) Len

func (s *Session) Len() int

Len returns the number of active sessions.

type SessionId

type SessionId int64

SessionId is the type for session IDs.

type StatResponse

type StatResponse struct {
	Type         string
	Size         int64
	LastModified time.Time
}

StatResponse is a response containing file information.

func (*StatResponse) IsDir

func (r *StatResponse) IsDir() bool

IsDir returns true if the file is a directory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL