]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - warc/record.go
Modern rand.Read never fails
[tofuproxy.git] / warc / record.go
index 3a9843571a05e53bb86e8756a09a8674aa7c0276..138f92cab6800442d974c3a2ec37868e7c6bb492 100644 (file)
@@ -1,20 +1,18 @@
-/*
-tofuproxy -- flexible HTTP proxy, TLS terminator, X.509 certificates
-             manager, WARC/Gemini browser
-Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
+//              manager, WARC/geminispace browser
+// Copyright (C) 2021-2025 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package warc
 
@@ -24,15 +22,13 @@ import (
 )
 
 type Record struct {
-       WARCPath string
-       Offset   int64
-       Size     int64
-
-       Hdr      Header
-       HdrLen   int
-       HdrLines []string
-
+       WARCPath      string
+       Hdr           Header
+       HdrLines      []string
        Continuations []*Record
+       Offset        int64
+       Size          int64
+       HdrLen        int
 }
 
 func (rec *Record) URI() string {
@@ -53,7 +49,7 @@ type SelfRecordReader struct {
 }
 
 func (srr *SelfRecordReader) Read(p []byte) (n int, err error) {
-       n, err = srr.rrr.Read(p)
+       n, err = srr.lr.Read(p)
        if err != nil {
                srr.Close()
        }
@@ -73,7 +69,11 @@ func (rec *Record) selfReader(noHdr bool, offsets []Offset) (*SelfRecordReader,
        if err != nil {
                return nil, err
        }
-       return &SelfRecordReader{lr: &io.LimitedReader{R: rrr, N: rec.Size}, rrr: rrr}, nil
+       size := rec.Size
+       if !noHdr {
+               size += int64(rec.HdrLen)
+       }
+       return &SelfRecordReader{lr: &io.LimitedReader{R: rrr, N: size}, rrr: rrr}, nil
 }
 
 type RecordReader struct {