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 ( ; ; )
|
for ( ; ; )
|
||||||
{
|
{
|
||||||
bool readCurr = reader.is.Next( &bufCurr, &sizeCurr );
|
bool readCurr = reader.is->Next( &bufCurr, &sizeCurr );
|
||||||
|
|
||||||
if ( readCurr )
|
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,
|
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();
|
os.writeAdler32();
|
||||||
}
|
}
|
||||||
|
|
||||||
Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibitProcessing ):
|
Reader::Reader( string const & fileName, EncryptionKey const & key, bool keepStream )
|
||||||
is( fileName.c_str(), key, Encryption::ZeroIv )
|
|
||||||
{
|
{
|
||||||
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 )
|
if ( header.version() >= FileFormatVersionFirstUnsupported )
|
||||||
throw exUnsupportedVersion();
|
throw exUnsupportedVersion();
|
||||||
|
|
||||||
Message::parse( info, is );
|
Message::parse( info, *is );
|
||||||
is.checkAdler32();
|
is->checkAdler32();
|
||||||
|
|
||||||
size_t payloadSize = 0;
|
size_t payloadSize = 0;
|
||||||
for ( int x = info.chunk_record_size(); x--; )
|
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 );
|
payload.resize( payloadSize );
|
||||||
|
|
||||||
if ( prohibitProcessing )
|
if ( keepStream )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sptr<Compression::EnDecoder> decoder = Compression::CompressionMethod::findCompression(
|
sptr<Compression::EnDecoder> decoder = Compression::CompressionMethod::findCompression(
|
||||||
|
@ -183,7 +186,7 @@ Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibi
|
||||||
{
|
{
|
||||||
void const * data;
|
void const * data;
|
||||||
int size;
|
int size;
|
||||||
if ( !is.Next( &data, &size ) )
|
if ( !is->Next( &data, &size ) )
|
||||||
{
|
{
|
||||||
decoder.reset();
|
decoder.reset();
|
||||||
throw exBundleReadFailed();
|
throw exBundleReadFailed();
|
||||||
|
@ -196,7 +199,7 @@ Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibi
|
||||||
if ( decoder->process( false ) )
|
if ( decoder->process( false ) )
|
||||||
{
|
{
|
||||||
if ( decoder->getAvailableInput() )
|
if ( decoder->getAvailableInput() )
|
||||||
is.BackUp( decoder->getAvailableInput() );
|
is->BackUp( decoder->getAvailableInput() );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +213,9 @@ Reader::Reader( string const & fileName, EncryptionKey const & key, bool prohibi
|
||||||
|
|
||||||
decoder.reset();
|
decoder.reset();
|
||||||
|
|
||||||
is.checkAdler32();
|
is->checkAdler32();
|
||||||
|
if ( is.get() )
|
||||||
|
is.reset();
|
||||||
|
|
||||||
// Populate the map
|
// Populate the map
|
||||||
char const * next = payload.data();
|
char const * next = payload.data();
|
||||||
|
|
|
@ -65,7 +65,7 @@ public:
|
||||||
DEF_EX( exDuplicateChunks, "Chunks with the same id found in a bundle", Ex )
|
DEF_EX( exDuplicateChunks, "Chunks with the same id found in a bundle", Ex )
|
||||||
|
|
||||||
Reader( string const & fileName, EncryptionKey const & key,
|
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
|
/// 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
|
/// was no such chunk in the bundle. chunkData may be enlarged but won't
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
string getPayload()
|
string getPayload()
|
||||||
{ return payload; }
|
{ return payload; }
|
||||||
|
|
||||||
EncryptedFile::InputStream is;
|
sptr< EncryptedFile::InputStream > is;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Creates a bundle by adding chunks to it until it's full, then compressing
|
/// Creates a bundle by adding chunks to it until it's full, then compressing
|
||||||
|
|
Loading…
Reference in New Issue