KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wxstream_helper.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef WXSTREAM_HELPER_H
21#define WXSTREAM_HELPER_H
22
23#include <vector>
24#include <wx/log.h>
25#include <wx/wfstream.h>
26
27
28static bool CopyStreamData( wxInputStream& inputStream, wxOutputStream& outputStream,
29 wxFileOffset size )
30{
31 constexpr size_t bufSize = 128 * 1024;
32 std::vector<wxChar> buf( bufSize );
33
34 wxFileOffset copiedData = 0;
35 wxFileOffset readSize = bufSize;
36
37 for( ; ; )
38 {
39 if(size != -1 && copiedData + readSize > size )
40 readSize = size - copiedData;
41
42 inputStream.Read( buf.data(), readSize );
43
44 size_t actuallyRead = inputStream.LastRead();
45 outputStream.Write( buf.data(), actuallyRead );
46
47 if( outputStream.LastWrite() != actuallyRead )
48 {
49 wxLogError( _("Failed to output data") );
50 //return false;
51 }
52
53 if( size == -1 )
54 {
55 if( inputStream.Eof() )
56 break;
57 }
58 else
59 {
60 copiedData += actuallyRead;
61
62 if( copiedData >= size )
63 break;
64 }
65 }
66
67 return true;
68}
69
70
71#endif // WXSTREAM_HELPER_H
#define _(s)
static bool CopyStreamData(wxInputStream &inputStream, wxOutputStream &outputStream, wxFileOffset size)