SQL Server
SQL Server
Check if a File is in Gzip Format
See more Gzip Examples
This example demonstrates how to use the ExamineFile method to determine whether a file is in Gzip format.
The method inspects the contents of the specified file and returns true if the file is recognized as a valid Gzip file, or false if it is not. This is useful for validating input files before attempting to decompress them.
If the method fails (for example, if the file does not exist or cannot be accessed), the CHECK_SUCCESS macro reports the error.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- This example demonstrates how to determine if a file is in Gzip format.
DECLARE @gzip int
EXEC @hr = sp_OACreate 'Chilkat.Gzip', @gzip OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- The file to examine:
DECLARE @filePath nvarchar(4000)
SELECT @filePath = 'test.gz'
-- Check if the file is a valid Gzip file:
DECLARE @isGzip int
EXEC sp_OAMethod @gzip, 'ExamineFile', @isGzip OUT, @filePath
IF @isGzip = 1
BEGIN
PRINT 'The file is a valid Gzip file.'
END
ELSE
BEGIN
PRINT 'The file isnot a Gzip file.'
END
EXEC @hr = sp_OADestroy @gzip
END
GO