Skip to content

Commit

Permalink
update read file action extension (#114)
Browse files Browse the repository at this point in the history
* update read file server

* use extension data to read file action

* fix a bug

* update read file action with extension
  • Loading branch information
jiuquxzy authored Apr 25, 2024
1 parent 1c4eaa3 commit 1597062
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions core/readfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,15 @@ func (e *protocols) ReadFileAction(id peer.ID, roothash, datahash, path string,
})
}

func (e *protocols) ReadFileActionWithExtension(id peer.ID, roothash, datahash, path string, size int64, extData []byte) error {
var err error
var offset int64
var fstat fs.FileInfo
var f *os.File

if fstat, err = os.Stat(path); err == nil && fstat.IsDir() {
return fmt.Errorf("%s is a directory", path)
}
f, err = os.Create(path)
if err != nil {
return errors.Wrapf(err, "[create file]")
}
defer f.Close()
defer f.Sync()
func (e *protocols) ReadFileActionWithExtension(id peer.ID, roothash, datahash string, writer io.Writer, extData []byte) error {
req := &pb.ReadfileRequest{
Roothash: roothash,
Datahash: datahash,
Offset: offset,
//add extension data
Roothash: roothash,
Datahash: datahash,
ExtendData: extData,
MessageData: e.ReadFileProtocol.NewMessageData(uuid.New().String(), false),
}
return e.readFileAction(id, req, func(req *pb.ReadfileRequest, resp *readMsgResp) error {
num, err := f.Write(resp.Data[:resp.Length])
num, err := writer.Write(resp.Data[:resp.Length])
if err != nil {
return errors.Wrapf(err, "[write file]")
}
Expand Down

0 comments on commit 1597062

Please sign in to comment.