From 340736e4ab0c040b64ca83aa82388962af43e9c4 Mon Sep 17 00:00:00 2001 From: "reza.duty" Date: Fri, 27 Oct 2023 19:34:39 +0330 Subject: [PATCH] Update 2023-10-27-top-60-compression-method.md --- .../2023-10-27-top-60-compression-method.md | 158 +++++++++++++++++- 1 file changed, 156 insertions(+), 2 deletions(-) diff --git a/_posts/2023-10-27-top-60-compression-method.md b/_posts/2023-10-27-top-60-compression-method.md index 3cd4ca6..030b849 100644 --- a/_posts/2023-10-27-top-60-compression-method.md +++ b/_posts/2023-10-27-top-60-compression-method.md @@ -81,7 +81,28 @@ rating: 4.5 ![compress methods](/assets/images/compress-methods.png) +### NTFS +``` +@echo off +setlocal enabledelayedexpansion + +:: Compress the file or directory +compact /c "path_to_file_or_directory" + +:: Slice the compressed file using PowerShell +powershell -command "& { + $filename = 'path_to_compressed_file'; + $chunkSize = 10MB; + $counter = 1; + + Get-Content $filename -ReadCount ([math]::Round((Get-Item $filename).length / $chunkSize)) | + ForEach-Object { + Set-Content ($filename + '.' + $counter) -Value $_; + $counter++ + } +}" +``` ### SquashFS @@ -223,6 +244,8 @@ if __name__ == "__main__": compress_and_slice(input_file, output_base, slice_size) ``` + + python script_name.py input.txt compressed 100000 ### tar @@ -266,6 +289,139 @@ makecab /D CompressionType=MSZIP /D MaxDiskSize=100M input_file output_file.cab ``` +### Xpress Compression (Template) + +``` +#include "pch.h" +#include "MainPage.xaml.h" +#include "SampleConfiguration.h" +#include "CompressionUtils.h" + +using namespace Windows::Storage; +using namespace Windows::Storage::Pickers; +using namespace Windows::Storage::Streams; +using namespace Windows::Storage::Compression; + +using namespace concurrency; + +#pragma region ReadStreamTask implementation +// We can't derive from task because we need to initialize task_completion_event before task itself. +struct ReadStreamTask::ReadStreamTaskImpl { + ReadStreamTaskImpl(IInputStream^ Stream, std::vector &Destination) : + _Destination(Destination), + _Reader(ref new DataReader(Stream)), + _CompletionEvent() + { + } + + task RunTask() + { + ReadChunk(); + return create_task(_CompletionEvent).then([this] + { + // Schedule resource deallocation + std::unique_ptr thisHolder(this); + + // Prevent user provided stream from being closed + _Reader->DetachStream(); + + // Move data out + _Destination = std::move(_StreamData); + + return _Destination.size(); + }); + } + + void ReadChunk() + { + // LoadAsync itself could throw exception if IAsyncOperation couldn't be created with + // given parameters in a current state + try + { + // Read data into the data reader + _StreamData.reserve(_StreamData.size() + MinReadChunkSize); + create_task(_Reader->LoadAsync(static_cast(_StreamData.capacity() - _StreamData.size()))) + + // Then store it to the result vector + .then([this](task BytesRead) + { + try + { + // exception is thrown here if LoadAsync operation has been completed with an error + auto bytesRead = BytesRead.get(); + if (bytesRead) + { + // Store chunk of data in the result vector. + auto newData = ref new Platform::Array(bytesRead); + _Reader->ReadBytes(newData); + + _StreamData.insert(_StreamData.end(), newData->begin(), newData->end()); + + // Then recurse to read next chunk. + ReadChunk(); + } + else + { + // End of stream is reached - complete top level task with the data we've read so far + + // make sure that _CompletionEvent outlives continuation which deletes this ReadStreamTaskImpl + auto completionEvent = _CompletionEvent; + completionEvent.set(); + } + } + catch (...) + { + // Schedule resource deallocation + std::unique_ptr thisHolder(this); + + _CompletionEvent.set_exception(std::current_exception()); + } + }); + } + catch (...) + { + // Schedule resource deallocation + std::unique_ptr thisHolder(this); + + _CompletionEvent.set_exception(std::current_exception()); + } + } + + // All data members are accessed serially - no synchronization is done + std::vector &_Destination; + DataReader^ _Reader; + std::vector _StreamData; + + task_completion_event _CompletionEvent; +}; + +ReadStreamTask::ReadStreamTask(IInputStream^ Stream, std::vector &Destination) : + _Impl(new ReadStreamTaskImpl(Stream, Destination)) +{ +} + +ReadStreamTask::ReadStreamTask(const ReadStreamTask& Task) : + _Impl(Task._Impl) +{ +} + +ReadStreamTask &ReadStreamTask::operator=(const ReadStreamTask& Task) +{ + _Impl = Task._Impl; + return *this; +} + +task ReadStreamTask::RunTask() +{ + return _Impl->RunTask(); +} +#pragma endregion +``` + + +https://learn.microsoft.com/en-us/windows/win32/fileio/file-compression-and-decompression + + ### LZMS ``` @@ -328,8 +484,6 @@ and ``` openssl enc -rc4 -in myarchive.7z -out myarchive_encrypted.7z -pass pass:YourPassword ``` -### -compress multiple documents on the DCCC and DNC ### cab