mirror of https://github.com/vitalif/zbackup
Resolved #58
parent
6b0fd79da0
commit
335db15909
27
bundle.cc
27
bundle.cc
|
@ -54,7 +54,7 @@ void Creator::write( std::string const & fileName, EncryptionKey const & key,
|
|||
|
||||
for ( ; ; )
|
||||
{
|
||||
bool readCurr = reader.is.Next( &bufCurr, &sizeCurr );
|
||||
bool readCurr = reader.is->Next( &bufCurr, &sizeCurr );
|
||||
|
||||
if ( readCurr )
|
||||
{
|
||||
|
@ -88,6 +88,9 @@ void Creator::write( std::string const & fileName, EncryptionKey const & key,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( reader.is.get() )
|
||||
reader.is.reset();
|
||||
}
|
||||
|
||||
void Creator::write( Config const & config, std::string const & fileName,
|
||||
|
@ -151,18 +154,18 @@ void Creator::write( Config const & config, std::string const & fileName,
|
|||
os.writeAdler32();
|
||||
}
|
||||
|
||||
Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibitProcessing ):
|
||||
is( fileName.c_str(), key, Encryption::ZeroIv )
|
||||
Reader::Reader( string const & fileName, EncryptionKey const & key, bool keepStream )
|
||||
{
|
||||
is.consumeRandomIv();
|
||||
is = new EncryptedFile::InputStream( fileName.c_str(), key, Encryption::ZeroIv );
|
||||
is->consumeRandomIv();
|
||||
|
||||
Message::parse( header, is );
|
||||
Message::parse( header, *is );
|
||||
|
||||
if ( header.version() >= FileFormatVersionFirstUnsupported )
|
||||
throw exUnsupportedVersion();
|
||||
|
||||
Message::parse( info, is );
|
||||
is.checkAdler32();
|
||||
Message::parse( info, *is );
|
||||
is->checkAdler32();
|
||||
|
||||
size_t payloadSize = 0;
|
||||
for ( int x = info.chunk_record_size(); x--; )
|
||||
|
@ -170,7 +173,7 @@ Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibi
|
|||
|
||||
payload.resize( payloadSize );
|
||||
|
||||
if ( prohibitProcessing )
|
||||
if ( keepStream )
|
||||
return;
|
||||
|
||||
sptr<Compression::EnDecoder> decoder = Compression::CompressionMethod::findCompression(
|
||||
|
@ -183,7 +186,7 @@ Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibi
|
|||
{
|
||||
void const * data;
|
||||
int size;
|
||||
if ( !is.Next( &data, &size ) )
|
||||
if ( !is->Next( &data, &size ) )
|
||||
{
|
||||
decoder.reset();
|
||||
throw exBundleReadFailed();
|
||||
|
@ -196,7 +199,7 @@ Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibi
|
|||
if ( decoder->process( false ) )
|
||||
{
|
||||
if ( decoder->getAvailableInput() )
|
||||
is.BackUp( decoder->getAvailableInput() );
|
||||
is->BackUp( decoder->getAvailableInput() );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -210,7 +213,9 @@ Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibi
|
|||
|
||||
decoder.reset();
|
||||
|
||||
is.checkAdler32();
|
||||
is->checkAdler32();
|
||||
if ( is.get() )
|
||||
is.reset();
|
||||
|
||||
// Populate the map
|
||||
char const * next = payload.data();
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
DEF_EX( exDuplicateChunks, "Chunks with the same id found in a bundle", Ex )
|
||||
|
||||
Reader( string const & fileName, EncryptionKey const & key,
|
||||
bool prohibitProcessing = false );
|
||||
bool keepStream = false );
|
||||
|
||||
/// Reads the chunk into chunkData and returns true, or returns false if there
|
||||
/// was no such chunk in the bundle. chunkData may be enlarged but won't
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
string getPayload()
|
||||
{ return payload; }
|
||||
|
||||
EncryptedFile::InputStream is;
|
||||
sptr< EncryptedFile::InputStream > is;
|
||||
};
|
||||
|
||||
/// Creates a bundle by adding chunks to it until it's full, then compressing
|
||||
|
|
Loading…
Reference in New Issue