![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Add Custom Extra Data to a Gzip FileThis example demonstrates how to use the The hex string represents the raw bytes to embed in the Gzip metadata. When a compression method is called, this data is included in the Gzip header. The example also shows how to retrieve the metadata using
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @success int SELECT @success = 0 -- This example demonstrates how to include custom extra data -- in the Gzip header when compressing. -- The extra data is provided as a hex-encoded string. DECLARE @gzip int EXEC @hr = sp_OACreate 'Chilkat.Gzip', @gzip OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @json int EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT -- Set extra data using a hex string. -- This example represents 4 bytes: 00 01 02 03 EXEC sp_OAMethod @gzip, 'SetExtraData', @success OUT, '00010203', 'hex' IF @success = 0 BEGIN EXEC sp_OAGetProperty @gzip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @gzip EXEC @hr = sp_OADestroy @json RETURN END -- Compress a file so the extra data is embedded in the Gzip header: DECLARE @inputFile nvarchar(4000) SELECT @inputFile = 'example.txt' DECLARE @outputFile nvarchar(4000) SELECT @outputFile = 'example.txt.gz' EXEC sp_OAMethod @gzip, 'CompressFile', @success OUT, @inputFile, @outputFile IF @success = 0 BEGIN EXEC sp_OAGetProperty @gzip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @gzip EXEC @hr = sp_OADestroy @json RETURN END PRINT 'Gzip file created with extra data.' -- (Optional) Retrieve the metadata to verify: EXEC sp_OAMethod @gzip, 'GetGzipInfo', @success OUT, @outputFile, @json IF @success = 0 BEGIN EXEC sp_OAGetProperty @gzip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @gzip EXEC @hr = sp_OADestroy @json RETURN END PRINT 'Metadata JSON:' EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @gzip EXEC @hr = sp_OADestroy @json END GO |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.