GZ I P - Decode
This is a powerful addition to your MetaTrader 5 toolkit designed to optimize market analysis and performance. This library provides a collection of modular, reusable code. It is utilized by developers to organize common functions, allowing for the integration of complex logic across multiple Expert Advisors, indicators, or scripts without the need for code duplication.
How to Setup and Use GZ I P - Decode
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
Description & Settings
The library allows you to decrypt GZIP archives from *.gz files or responses from sites compressed with this format. Tested on files with up to 0.5 GB of text packed in them.
The library can automatically check by the flag in the 4th byte whether the archive is a compressed file or compressed data from the site, in the second case there is no file name in the data.
Input data for decompression should be represented in an array of char type.
The terminal function CryptDecode(CRYPT_ARCH_ZIP, tmp, key, tx) is used for decompression;
The GZIP class contains methods:
- checks against the first three characters of the received data to see if it is compressed in GZIP format.
After this check, one of the overloads of the unGZIP method can be called:
the preferred use case in terms of speed and memory consumption. During decompression, the char array tx is filled. Then data from it can be processed by CSV or JSON parser. This way we get the result without gluing the array into a string and then dividing it by strings or other characters.
If you still need to get a string, you can use one of the overloads:
return true if unpacking is successful, the unpacked string is in the string out
or
return string. If unpacking fails, the string will be empty.
Care should be taken when using concatenation of data into a single string. If you unpacked an archive with 0.5GB of data, the string will require another 0.5GB, then you can split it into an array of strings, which will require another 0.5GB. Plus the time cost of all these operations.
Example use case for reading compressed data from a website and then reading from a file: (this script is attached for download)
This example reads a file from the files folder, and decompresses it into an array. The first and last 100 characters from the unpacked file are printed. The array can then be sent to a CSV or JSON parser. For JSON there is JASON library in kodobase. It can parse data received as a char array.
Example of output when unpacking a compressed CSV file of 120 MB, the source file is 463 MB:
Unpacking took about 1.2 seconds.