Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Unzip Binary File to StreamDemonstrates how to unzip a large binary file to a stream to allow the application to process the uncompressed bytes chunk by chunk. Note: This example requires Chilkat v9.5.0.67 or greater.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This requires the Chilkat Zip API to have been previously unlocked. -- See Unlock Chilkat Zip for sample code. DECLARE @zip int -- Use "Chilkat_9_5_0.Zip" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Zip', @zip OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- First open a .zip. DECLARE @success int EXEC sp_OAMethod @zip, 'OpenZip', @success OUT, 'qa_data/zips/big.zip' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip RETURN END -- Get the entry to be unzipped to a stream.. DECLARE @entry int EXEC sp_OAMethod @zip, 'GetEntryByIndex', @entry OUT, 0 EXEC sp_OAGetProperty @zip, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip RETURN END DECLARE @dataStream int -- Use "Chilkat_9_5_0.Stream" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Stream', @dataStream OUT DECLARE @unzipTask int EXEC sp_OAMethod @entry, 'UnzipToStreamAsync', @unzipTask OUT, @dataStream EXEC sp_OAGetProperty @entry, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @entry, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @entry EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @dataStream RETURN END -- Start the background unzip thread. EXEC sp_OAMethod @unzipTask, 'Run', @success OUT -- We'll read the uncompressed data chunk-by-chunk and write to an output file. DECLARE @fac int -- Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @fac OUT EXEC sp_OAMethod @fac, 'OpenForWrite', @success OUT, 'qa_output/out.dat' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @fac, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @entry EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @dataStream EXEC @hr = sp_OADestroy @fac RETURN END -- Read the stream. (this is reading the unzipped file data) DECLARE @bd int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT EXEC sp_OAGetProperty @dataStream, 'EndOfStream', @iTmp0 OUT WHILE @iTmp0 <> 1 BEGIN -- Get the next chunk of decompressed bytes. EXEC sp_OAMethod @dataStream, 'ReadBd', @success OUT, @bd -- Do something with it.. -- In this simple example, we'll just write to the file. EXEC sp_OAMethod @fac, 'FileWriteBd', @success OUT, @bd, 0, 0 -- Clear for the next read. EXEC sp_OAMethod @bd, 'Clear', @success OUT END EXEC sp_OAMethod @fac, 'FileClose', NULL EXEC @hr = sp_OADestroy @entry EXEC @hr = sp_OADestroy @unzipTask PRINT 'Success.' EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @dataStream EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @bd END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.