William Petit
8e574c299b
All checks were successful
arcad/edge/pipeline/pr-master This commit looks good
42 lines
646 B
Go
42 lines
646 B
Go
package blob
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type ReadBlobArgs struct {
|
|
ReaderID ReaderID
|
|
Length int
|
|
}
|
|
|
|
type ReadBlobReply struct {
|
|
Data []byte
|
|
Read int
|
|
EOF bool
|
|
}
|
|
|
|
func (s *Service) ReadBlob(ctx context.Context, args *ReadBlobArgs, reply *ReadBlobReply) error {
|
|
reader, err := s.getOpenedReader(args.ReaderID)
|
|
if err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
buff := make([]byte, args.Length)
|
|
|
|
read, err := reader.Read(buff)
|
|
if err != nil && !errors.Is(err, io.EOF) {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
*reply = ReadBlobReply{
|
|
Read: read,
|
|
Data: buff,
|
|
EOF: errors.Is(err, io.EOF),
|
|
}
|
|
|
|
return nil
|
|
}
|