From fa690ad3d7637864873ec9a0f7ab128b898bf3c4 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 18 Feb 2013 21:29:19 -0800 Subject: [PATCH] schema: support bytes.Reader and strings.Reader in FileTime Change-Id: Ib42a0478782f7e421e3f3125b1fc876d27d6ee68 --- pkg/schema/schema.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index e403e7bc8..2d8054014 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -30,7 +30,6 @@ import ( "fmt" "hash" "io" - "log" "os" "reflect" "strconv" @@ -719,6 +718,19 @@ func findSize(v interface{}) (size int64, ok bool) { }); ok { return sz.Size(), true } + // For bytes.Reader, strings.Reader, etc: + if li, ok := v.(interface { + Len() int + }); ok { + ln := int64(li.Len()) // unread portion, typically + // If it's also a seeker, remove add any seek offset: + if sk, ok := v.(io.Seeker); ok { + if cur, err := sk.Seek(0, 1); err == nil { + ln += cur + } + } + return ln, true + } return 0, false } @@ -747,12 +759,10 @@ func FileTime(f io.ReaderAt) (time.Time, error) { r := io.NewSectionReader(f, 0, size) ex, err := exif.Decode(r) if err != nil { - fmt.Printf("%v\n", err) return defaultTime() } ct, err = ex.DateTime() if err != nil { - log.Printf("Error with DateTime in EXIF: %v", err) return defaultTime() } return ct, nil