About EasyMorph Tutorials & Examples Web-help

Bzip2 or gzip format

Hi all,
anyone knows how to create with easymorph an archive file with bzip2 or gzip format?

thank you
claudio

You can archive to GZip with PowerShell. Here is a sample project and the script from it:

gzip.morph (1.8 KB)

$File = "{File name}"
$srcFile = Get-Item -Path $File
$newFileName = "$($srcFile.FullName).gz"

try
{
    $srcFileStream = New-Object System.IO.FileStream($srcFile.FullName,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read))
    $dstFileStream = New-Object System.IO.FileStream($newFileName,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None))
    $gzip = New-Object System.IO.Compression.GZipStream($dstFileStream,[System.IO.Compression.CompressionMode]::Compress)
    $srcFileStream.CopyTo($gzip)
} 
catch
{
    Write-Host "$_.Exception.Message"
}
finally
{
    $gzip.Dispose()
    $srcFileStream.Dispose()
    $dstFileStream.Dispose()
}

The script is taken here: https://securitytidbits.wordpress.com/2017/04/14/powershell-and-gzip-compression/

Hi Dmitry and thanks,
I was not able to use this script, too many errors, something is probably missing on my server.

Anyway, I solved with 7zip installation and a very simple script:
C:“Program Files”\7-Zip\7z.exe a -tgzip C:\Users\claudio.murano\Desktop\SGtest\prova.gz C:\Users\claudio.murano\Desktop\SGtest\prova.txt
this script call .exe, then we have the command a(=add file), command -t used to define a format + gzip format, finally the archive destination path and the path of file to archive.

Attached the sample project.
gzip_7zip.morph (1.2 KB)

Thank you
Claudio

1 Like
To learn more about EasyMorph visit easymorph.com.