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) Gzip Compress In Memory and Base64 EncodeDemonstrates how to Gzip compress in-memory data and then encode the compressed data to base64.
-- 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) -- This example assumes the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @gzip int -- Use "Chilkat_9_5_0.Gzip" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Gzip', @gzip OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- This example will load a file into the fileData object. -- Your application might load fileData from other sources.. DECLARE @fileData int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @fileData OUT DECLARE @success int EXEC sp_OAMethod @fileData, 'LoadFile', @success OUT, 'qa_data/xml/hamlet.xml' IF @success <> 1 BEGIN PRINT 'Failed to load file.' EXEC @hr = sp_OADestroy @gzip EXEC @hr = sp_OADestroy @fileData RETURN END -- In-place compress the contents of fileData EXEC sp_OAMethod @gzip, 'CompressBd', @success OUT, @fileData IF @success <> 1 BEGIN EXEC sp_OAGetProperty @gzip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @gzip EXEC @hr = sp_OADestroy @fileData RETURN END -- Get the base64 encoded compressed data (in a single line). DECLARE @strBase64 nvarchar(4000) EXEC sp_OAMethod @fileData, 'GetEncoded', @strBase64 OUT, 'base64' PRINT @strBase64 PRINT '--------' -- To get the base64 in multiple lines, as it might appear in MIME, -- use "base64-mime". DECLARE @strBase64MultiLine nvarchar(4000) EXEC sp_OAMethod @fileData, 'GetEncoded', @strBase64MultiLine OUT, 'base64-mime' PRINT @strBase64MultiLine EXEC @hr = sp_OADestroy @gzip EXEC @hr = sp_OADestroy @fileData END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.