![]() |
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) Retrieve Metadata from a Gzip FileSee more Gzip ExamplesThis example demonstrates how to use the The method reads the Gzip header and extracts any available metadata, including the embedded filename, comment, and optional extra data. The extracted information is returned in a Because these fields are optional, the example checks for the existence of each JSON member using Note: This example requires Chilkat v11.5.0 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) DECLARE @success int SELECT @success = 0 -- This example demonstrates how to retrieve metadata embedded in a Gzip file. 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 -- The Gzip file to examine: DECLARE @gzPath nvarchar(4000) SELECT @gzPath = 'example.txt.gz' -- Get the metadata information: EXEC sp_OAMethod @gzip, 'GetGzipInfo', @success OUT, @gzPath, @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 -- Output the JSON containing metadata: PRINT 'Gzip metadata JSON:' EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- Access individual fields only if they exist: EXEC sp_OAMethod @json, 'HasMember', @iTmp0 OUT, 'filename' IF @iTmp0 = 1 BEGIN DECLARE @filename nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @filename OUT, 'filename' PRINT 'Filename: ' + @filename END EXEC sp_OAMethod @json, 'HasMember', @iTmp0 OUT, 'comment' IF @iTmp0 = 1 BEGIN DECLARE @comment nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @comment OUT, 'comment' PRINT 'Comment: ' + @comment END EXEC sp_OAMethod @json, 'HasMember', @iTmp0 OUT, 'extraData' IF @iTmp0 = 1 BEGIN DECLARE @extraData nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @extraData OUT, 'extraData' PRINT 'ExtraData (Base64): ' + @extraData END EXEC @hr = sp_OADestroy @gzip EXEC @hr = sp_OADestroy @json END GO |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.