Skip to content

Commit

Permalink
Update 2023-10-27-top-60-compression-method.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaduty authored Oct 27, 2023
1 parent 57cb56b commit 340736e
Showing 1 changed file with 156 additions and 2 deletions.
158 changes: 156 additions & 2 deletions _posts/2023-10-27-top-60-compression-method.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<byte> &Destination) :
_Destination(Destination),
_Reader(ref new DataReader(Stream)),
_CompletionEvent()
{
}
task<size_t> RunTask()
{
ReadChunk();
return create_task(_CompletionEvent).then([this]
{
// Schedule resource deallocation
std::unique_ptr<ReadStreamTaskImpl> 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<unsigned int>(_StreamData.capacity() - _StreamData.size())))
// Then store it to the result vector
.then([this](task<unsigned int> 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<byte>(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<ReadStreamTaskImpl> thisHolder(this);
_CompletionEvent.set_exception(std::current_exception());
}
});
}
catch (...)
{
// Schedule resource deallocation
std::unique_ptr<ReadStreamTaskImpl> thisHolder(this);
_CompletionEvent.set_exception(std::current_exception());
}
}
// All data members are accessed serially - no synchronization is done
std::vector<byte> &_Destination;
DataReader^ _Reader;
std::vector<byte> _StreamData;
task_completion_event<void> _CompletionEvent;
};
ReadStreamTask::ReadStreamTask(IInputStream^ Stream, std::vector<byte> &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<size_t> ReadStreamTask::RunTask()
{
return _Impl->RunTask();
}
#pragma endregion
```


https://learn.microsoft.com/en-us/windows/win32/fileio/file-compression-and-decompression


### LZMS

```
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 340736e

Please sign in to comment.