-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for reading raw extracted data via a callback
Close issue #122
- Loading branch information
Showing
11 changed files
with
291 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// This is an open source non-commercial project. Dear PVS-Studio, please check it. | ||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com | ||
|
||
/* | ||
* bit7z - A C++ static library to interface with the 7-zip shared libraries. | ||
* Copyright (c) 2014-2024 Riccardo Ostani - All Rights Reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <utility> | ||
|
||
#include "internal/crawoutstream.hpp" | ||
|
||
namespace bit7z { | ||
|
||
CRawOutStream::CRawOutStream( RawDataCallback callback ) : mOutputCallback{ std::move( callback ) } {} | ||
|
||
COM_DECLSPEC_NOTHROW | ||
STDMETHODIMP CRawOutStream::Write( const void* data, UInt32 size, UInt32* processedSize ) noexcept { | ||
if ( processedSize != nullptr ) { | ||
*processedSize = 0; | ||
} | ||
|
||
if ( size == 0 ) { | ||
return S_OK; | ||
} | ||
|
||
bool callbackResult = mOutputCallback( static_cast< const byte_t* >( data ), size ); | ||
|
||
if ( processedSize != nullptr ) { | ||
*processedSize = size; | ||
} | ||
|
||
return callbackResult ? S_OK : E_ABORT; | ||
} | ||
|
||
} // namespace bit7z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* bit7z - A C++ static library to interface with the 7-zip shared libraries. | ||
* Copyright (c) 2014-2024 Riccardo Ostani - All Rights Reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef CRAWOUTSTREAM_HPP | ||
#define CRAWOUTSTREAM_HPP | ||
|
||
#include "bitabstractarchivehandler.hpp" | ||
#include "internal/com.hpp" | ||
#include "internal/guids.hpp" | ||
#include "internal/macros.hpp" | ||
|
||
#include <7zip/IStream.h> | ||
|
||
#include <ostream> | ||
|
||
namespace bit7z { | ||
|
||
class CRawOutStream : public ISequentialOutStream, public CMyUnknownImp { | ||
public: | ||
explicit CRawOutStream( RawDataCallback callback ); | ||
|
||
CRawOutStream( const CRawOutStream& ) = delete; | ||
|
||
CRawOutStream( CRawOutStream&& ) = delete; | ||
|
||
auto operator=( const CRawOutStream& ) -> CRawOutStream& = delete; | ||
|
||
auto operator=( CRawOutStream&& ) -> CRawOutStream& = delete; | ||
|
||
MY_UNKNOWN_VIRTUAL_DESTRUCTOR( ~CRawOutStream() ) = default; | ||
|
||
// IOutStream | ||
BIT7Z_STDMETHOD( Write, void const* data, UInt32 size, UInt32* processedSize ); | ||
|
||
// NOLINTNEXTLINE(modernize-use-noexcept, modernize-use-trailing-return-type, readability-identifier-length) | ||
MY_UNKNOWN_IMP1( ISequentialOutStream ) //-V2507 //-V2511 //-V835 | ||
|
||
private: | ||
RawDataCallback mOutputCallback; | ||
}; | ||
|
||
} // namespace bit7z | ||
|
||
#endif // CRAWOUTSTREAM_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// This is an open source non-commercial project. Dear PVS-Studio, please check it. | ||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com | ||
|
||
/* | ||
* bit7z - A C++ static library to interface with the 7-zip shared libraries. | ||
* Copyright (c) 2014-2024 Riccardo Ostani - All Rights Reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "internal/rawdataextractcallback.hpp" | ||
|
||
#include "bitinputarchive.hpp" | ||
#include "bitpropvariant.hpp" | ||
#include "internal/crawoutstream.hpp" | ||
#include "internal/extractcallback.hpp" | ||
#include "internal/util.hpp" | ||
|
||
#include <cstdint> | ||
#include <ostream> | ||
#include <utility> | ||
|
||
using namespace NWindows; | ||
|
||
namespace bit7z { | ||
|
||
RawDataExtractCallback::RawDataExtractCallback( const BitInputArchive& inputArchive, RawDataCallback callback ) | ||
: ExtractCallback( inputArchive ), | ||
mCallback( std::move( callback ) ) {} | ||
|
||
void RawDataExtractCallback::releaseStream() { | ||
mCallbackStream.Release(); | ||
} | ||
|
||
auto RawDataExtractCallback::getOutStream( uint32_t index, ISequentialOutStream** outStream ) -> HRESULT { | ||
if ( isItemFolder( index ) ) { | ||
return S_OK; | ||
} | ||
|
||
// Get Name | ||
const BitPropVariant prop = itemProperty( index, BitProperty::Path ); | ||
tstring fullPath; | ||
|
||
if ( prop.isEmpty() ) { | ||
fullPath = kEmptyFileAlias; | ||
} else if ( prop.isString() ) { | ||
fullPath = prop.getString(); | ||
} else { | ||
return E_FAIL; | ||
} | ||
|
||
if ( mHandler.fileCallback() ) { | ||
mHandler.fileCallback()( fullPath ); | ||
} | ||
|
||
auto outStreamLoc = bit7z::make_com< CRawOutStream, ISequentialOutStream >( mCallback ); | ||
mCallbackStream = outStreamLoc; | ||
*outStream = outStreamLoc.Detach(); | ||
return S_OK; | ||
} | ||
|
||
} // namespace bit7z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* bit7z - A C++ static library to interface with the 7-zip shared libraries. | ||
* Copyright (c) 2014-2024 Riccardo Ostani - All Rights Reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef RAWDATAEXTRACTCALLBACK_HPP | ||
#define RAWDATAEXTRACTCALLBACK_HPP | ||
|
||
#include "bitabstractarchivehandler.hpp" | ||
#include "internal/extractcallback.hpp" | ||
|
||
#include <cstdint> | ||
|
||
namespace bit7z { | ||
|
||
class BitInputArchive; | ||
|
||
class RawDataExtractCallback final : public ExtractCallback { | ||
public: | ||
RawDataExtractCallback( const BitInputArchive& inputArchive, RawDataCallback callback ); | ||
|
||
RawDataExtractCallback( const RawDataExtractCallback& ) = delete; | ||
|
||
RawDataExtractCallback( RawDataExtractCallback&& ) = delete; | ||
|
||
auto operator=( const RawDataExtractCallback& ) -> RawDataExtractCallback& = delete; | ||
|
||
auto operator=( RawDataExtractCallback&& ) -> RawDataExtractCallback& = delete; | ||
|
||
~RawDataExtractCallback() override = default; | ||
|
||
private: | ||
RawDataCallback mCallback; | ||
CMyComPtr< ISequentialOutStream > mCallbackStream; | ||
|
||
void releaseStream() override; | ||
|
||
auto getOutStream( std::uint32_t index, ISequentialOutStream** outStream ) -> HRESULT override; | ||
}; | ||
|
||
} // namespace bit7z | ||
|
||
#endif // RAWDATAEXTRACTCALLBACK_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.