rusty-ferris-club / decompress Goto Github PK
View Code? Open in Web Editor NEWExtracting archives made easy for Rust ๐ฆ
License: Apache License 2.0
Extracting archives made easy for Rust ๐ฆ
License: Apache License 2.0
For a cheap test before decompression, when going over a massive list of files, it may be preferred to test for decompression before attempting it.
While there's no difference in performance, the API might be useful for making decisions in other part of program logic for some users.
On the face of it, there's nothing special regex
is doing when detecting file type based on extension. It can be easily replaced with checking the end of the string, or parsing out the path using std
only.
See this feedback: cargo-bins/cargo-binstall#617 (comment)
The various decompressors use a "central" error enum, which can convert from named and specific error types. Although this is the recommended and acceptable best practice, it makes for an overly verbose coding of an error ergonomics story.
anyhow
will chain, wrap, errors, and encourage and allow for adding contexts, which is something we need here.
the only drawback of using anyhow in libraries is that we cannot expose any anyhow type in the public API.
This is why we suggest a refactoring: use anyhow
for all internal error handling and propagation, but convert it to a final Error
for the public API.
Notes:
anyhow
first, see how using context
can be cool and nice for "attaching" error informationResult
types to anyhow::Result
, this is supposed to be easyAPI
and use an std::Result
. this means you need to now convert from anyhow::Result
to a standard one. you can use the existing thiserror
library to do thatUse neon to wrap the main decompress API for node.js. This does not require any knowledge of decompress other than its public API, and the API lend itself to FFI very well.
Your suggestion here
Just like in the npm
version of decompress
: https://github.com/kevva/decompress#filter
The idea is to let users:
filter
)map
)There are two primary challenges:
Opts
. It can be an Fn
signature, or a trait called FilterMap
which implements an identity filter
and map
by default, and then passed through a Box<dyn ..>
Add an option to detect the compressor from magic bytes, instead of extensions.
This means every decompressor should now have an additional test_magic
which applies magic number detection (for relevant archive types) and returns if it's compatible for decompression.
After this is done we will have two strategies:
The public API should allow to choose a strategy explicitly, or to order the strategies in "magic, fallback to extension" or "extension, fallback to magic". This may incorporate a small refactor in how decompressors are tested for validity.
In addition, including magic bytes now opens up the question of "what to do if no decompressors are found?". For example, it's completely viable for no magic bytes to exist, which may mean this is an uncompressed file.
If this is an uncompressed file, should we copy it to target folder? some users would prefer that over "no decompressor found". This kind of result type ("no decompressor", "copied", etc.) should be modeled and refactored as well.
A clever trick is to add a "PassthroughDecompressor" which is added to the stack, and so this one will copy files when no decompressor found.
See here: cargo-bins/cargo-binstall#617 (comment)
There's a println in the find_decompressor function of decompress 0.6.0.
It definitely shouldn't be there, at least not for the finished product.
Windows
1. Use decompress. Specifically the can_decompress function.
Add the following decompressors:
Which are standalone, only compress a single file, they have no concept of file listing or "archiving" like tar.
Similar to the recently added gz
decompressor: 651effa
Important:
tar.<..>
decompressor in the decompressor array stack, so that only if it's not a tar.<something>
file, then it will decompress.gz
decompressor to start withA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.