file

package module
v0.0.0-...-3933754 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

README

Go File License GoDoc

forked from asim/go-file

主要是在原项目上增加上传、查看目录等功能

使用

Server
import "github.com/laoqiu/go-file"

service := micro.NewService(
	micro.Name("go.micro.srv.file"),
)

proto.RegisterFileHandler(service.Server(), file.NewHandler("/tmp"))

service.Init()
service.Run()
Client
import "github.com/laoqiu/go-file"

// use new service or default client
service := micro.NewService()
service.Init()

client := file.NewClient("go.micro.srv.file", service.Client())
client.Download("remote.file", "local.file")

client.Upload("local.file", "upload.file")

Hand Wavy Bench

Local hand wavy benchmarks for rough estimates on transfer speed

size time taken
1mb 15.590542ms
8mb 75.184788ms
64mb 516.236417ms
128mb 1.141906576s
1024mb 9.794891634s

Using connection pooling and caching selector

size time taken
1mb 13.521179ms
8mb 53.160487ms
64mb 415.388025ms
128mb 889.409332ms
512mb 4.177052391s
1024mb 8.347038098s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(readDir string) proto.FileHandler

NewHandler is a handler that can be registered with a micro Server

func RegisterHandler

func RegisterHandler(s server.Server, readDir string)

RegisterHandler is a convenience method for registering a handler

Types

type Client

type Client interface {
	Open(ctx context.Context, filename string, new bool) (int64, error)
	Stat(ctx context.Context, filename string) (*proto.StatResponse, error)
	GetBlock(ctx context.Context, sessionId, blockId int64) ([]byte, error)
	Read(ctx context.Context, sessionId int64, buf []byte) (int, error)
	ReadAt(ctx context.Context, sessionId, offset, size int64) ([]byte, error)
	Close(ctx context.Context, sessionId int64) error
	Download(filename, saveFile string) error
	DownloadAt(ctx context.Context, filename, saveFile string, blockId int) error
	Upload(localfile, filename string) error
	UploadAt(ctx context.Context, localfile, filename string, blockId int) error
	UploadStream(ctx context.Context, b []byte, filename string, blockId int) error
	Remove(ctx context.Context, filename string) error
}

Client is the client interface to access files

func NewClient

func NewClient(service string, c client.Client) Client

NewClient returns a new Client which uses a micro Client

Directories

Path Synopsis
Package file is a generated protocol buffer package.
Package file is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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