Skip to content

Commit

Permalink
FET: Support generic readers that have the len interface
Browse files Browse the repository at this point in the history
  • Loading branch information
akissa committed Feb 1, 2022
1 parent 5bffc9c commit 85e8af4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions sophie.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Sophie - Golang Sophie protocol implementation
package sophie

import (
"bytes"
"context"
"fmt"
"io"
Expand All @@ -34,6 +33,10 @@ const (
tcpDirErr = "Scanning directories not supported on a TCP connection"
)

type readerWithLen interface {
Len() int
}

// Response is the response from the server
type Response struct {
Filename string
Expand Down Expand Up @@ -192,11 +195,7 @@ func (c *Client) readerCmd(ctx context.Context, i io.Reader) (r *Response, err e
defer tc.Close()

switch v := i.(type) {
case *bytes.Buffer:
clen = int64(v.Len())
case *bytes.Reader:
clen = int64(v.Len())
case *strings.Reader:
case readerWithLen:
clen = int64(v.Len())
case *os.File:
stat, err = v.Stat()
Expand Down

0 comments on commit 85e8af4

Please sign in to comment.