OpenCPN Partial API docs
Loading...
Searching...
No Matches
chartdata_input_stream.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2016 David S. Register *
3 * Copyright (C) 2016 Sean D'Epagnier *
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; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#include "config.h"
26#include <wx/ffile.h>
27#include <wx/string.h>
28#include <wx/wfstream.h>
29
30#ifdef OCPN_USE_LZMA
31#include <lzma.h>
32
36class wxCompressedFFileInputStream : public wxInputStream {
37public:
38 wxCompressedFFileInputStream(const wxString &fileName);
39 virtual ~wxCompressedFFileInputStream();
40
41 virtual bool IsOk() const {
42 return wxStreamBase::IsOk() && m_file->IsOpened();
43 }
44 bool IsSeekable() const { return false; }
45
46protected:
47 size_t OnSysRead(void *buffer, size_t size);
48 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
49 wxFileOffset OnSysTell() const;
50
51 wxFFile *m_file;
52 lzma_stream strm;
53
54private:
55 void init_lzma();
56
57 uint8_t inbuf[BUFSIZ];
58
59 wxDECLARE_NO_COPY_CLASS(wxCompressedFFileInputStream);
60};
61
62// non-seekable stream for either non-compressed or compressed files
63class ChartDataNonSeekableInputStream : public wxInputStream {
64public:
65 ChartDataNonSeekableInputStream(const wxString &fileName);
66 virtual ~ChartDataNonSeekableInputStream();
67
68 virtual bool IsOk() const { return m_stream->IsOk(); }
69 bool IsSeekable() const { return false; }
70
71protected:
72 size_t OnSysRead(void *buffer, size_t size);
73 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
74 wxFileOffset OnSysTell() const;
75
76private:
77 wxInputStream *m_stream;
78
79 wxDECLARE_NO_COPY_CLASS(ChartDataNonSeekableInputStream);
80};
81
82// seekable stream for either non-compressed or compressed files
83// it must decompress the file to a temporary file to make it seekable
84class ChartDataInputStream : public wxInputStream {
85public:
86 ChartDataInputStream(const wxString &fileName);
87 virtual ~ChartDataInputStream();
88
89 virtual bool IsOk() const { return m_stream->IsOk(); }
90 bool IsSeekable() const { return m_stream->IsSeekable(); }
91
92 wxString TempFileName() const { return m_tempfilename; }
93
94protected:
95 size_t OnSysRead(void *buffer, size_t size);
96 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
97 wxFileOffset OnSysTell() const;
98
99private:
100 wxString m_tempfilename;
101 wxInputStream *m_stream;
102
103 wxDECLARE_NO_COPY_CLASS(ChartDataInputStream);
104};
105
106#else
107
108typedef wxFFileInputStream ChartDataInputStream;
109typedef wxFFileInputStream ChartDataNonSeekableInputStream;
110
111#endif // OCPN_USE_LZMA
112
113bool DecompressXZFile(const wxString &input_path, const wxString &output_path);