]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - warc/record.go
Download link for 0.6.0 release
[tofuproxy.git] / warc / record.go
index d755acea56c7a1fbaeaed4d349ed111e3d930998..38181ab92724bc509f05402a87846624a5efe365 100644 (file)
@@ -1,20 +1,18 @@
-/*
-tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
-             manager, WARC/geminispace browser
-Copyright (C) 2021-2022 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-2024 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
 
@@ -53,7 +51,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 +71,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 {