]> Sergey Matveev's repositories - tofuproxy.git/blob - warc/open.go
22792d5b09513aed61972daf4443c60824e7fece
[tofuproxy.git] / warc / open.go
1 /*
2 tofuproxy -- flexible HTTP/WARC proxy with TLS certificates management
3 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package warc
19
20 import (
21         "fmt"
22         "io"
23         "path"
24 )
25
26 var UnZSTDPath = "/home/stargrave/work/tofuproxy/cmd/unzstd/unzstd"
27
28 type Offset struct {
29         Z int64 // Compressed frame size
30         U int64 // Its uncompressed size
31 }
32
33 type RawRecordReader interface {
34         io.ReadCloser
35         Offsets() []Offset
36 }
37
38 func Open(warcPath string, offsets []Offset, offset int64) (RawRecordReader, error) {
39         ext := path.Ext(warcPath)
40         switch ext {
41         case ".warc":
42                 return NewUncompressedReader(warcPath, offset)
43         case ".gz":
44                 return NewGZIPReader(warcPath, offsets, offset)
45         case ".zst":
46                 return NewCompressedReader(warcPath, UnZSTDPath, offsets, offset)
47         }
48         return nil, fmt.Errorf("unknown extension: %s", ext)
49 }