KiCad PCB EDA Suite
wxstream_helper.h File Reference
#include <vector>
#include <wx/log.h>
#include <wx/wfstream.h>

Go to the source code of this file.

Functions

static bool CopyStreamData (wxInputStream &inputStream, wxOutputStream &outputStream, wxFileOffset size)
 

Function Documentation

◆ CopyStreamData()

static bool CopyStreamData ( wxInputStream &  inputStream,
wxOutputStream &  outputStream,
wxFileOffset  size 
)
static

Definition at line 28 of file wxstream_helper.h.

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}
#define _(s)

References _.

Referenced by PCM_TASK_MANAGER::extract(), PCM_TASK_MANAGER::InstallFromFile(), and PROJECT_ARCHIVER::Unarchive().