From 6f35e663850742f1c0f3c34fe7d1318eb40687ae Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 9 Jun 2011 18:28:07 -0700 Subject: [PATCH] let file reader be closed --- lib/go/camli/schema/filereader.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/go/camli/schema/filereader.go b/lib/go/camli/schema/filereader.go index 936510c7f..d77b828d2 100644 --- a/lib/go/camli/schema/filereader.go +++ b/lib/go/camli/schema/filereader.go @@ -28,11 +28,14 @@ import ( var _ = log.Printf +const closedIndex = -1 +var errClosed = os.NewError("filereader is closed") + type FileReader struct { fetcher blobref.SeekFetcher ss *Superset - ci int // index into contentparts + ci int // index into contentparts, or -1 on closed ccon uint64 // bytes into current chunk already consumed remain int64 // bytes remaining @@ -73,7 +76,20 @@ func (fr *FileReader) FileSchema() *Superset { return fr.ss } +func (fr *FileReader) Close() os.Error { + if fr.ci == closedIndex { + return errClosed + } + fr.closeOpenBlobs() + fr.ci = closedIndex + return nil +} + func (fr *FileReader) Skip(skipBytes uint64) uint64 { + if fr.ci == closedIndex { + return 0 + } + wantedSkipped := skipBytes for skipBytes != 0 && fr.ci < len(fr.ss.ContentParts) { @@ -160,6 +176,10 @@ func (fr *FileReader) currentPart() (*ContentPart, os.Error) { } func (fr *FileReader) Read(p []byte) (n int, err os.Error) { + if fr.ci == closedIndex { + return 0, errClosed + } + cp, err := fr.currentPart() if err != nil { return 0, err