-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow more control over what to do with an archive's entries #20
Comments
Oh, I have a functioning It works by iterating over Overall I'm left feeling like using |
Well the clear benefit would be to have access to multiple combinators like The cleanest solution would be to have an FSM and to always move on each call. I took some time to draw (an approximation of) an FSM: This would be strongly typed and mistakes would be almost impossible during compile time. But it's very unergonomic for users to loop or iterate over entries this way... |
Well that state machine (and the ergonomics that come with it) is basically what you get with For implementing listing, you don't need a To get a clean (without I think I'll try playing around with this idea later and see how it looks. |
I tried to fork the Anyway I thought of a very hacky way we could make it work with the fn manipulate_immutable(s: &String) {
let s = s as *const String as *mut String;
let s = unsafe { &mut *s };
s.push('!');
}
fn main() {
let s = "Hello World!".to_string();
manipulate_immutable(&s);
println!("{}", s);
} Output: Unless I'm missing some UB, this might also be an option. I believe this wouldn't be thread safe... |
Unless I'm missing something, that's what I did in my implementation by using It works, but the problem with that is that it allows the user to try to process the entry multiple times. Archive::new("archive.rar").extract_to(".").unwrap()
.for_each(|unprocessed_entry| {
let result = unprocessed_entry.as_ref().unwrap().extract();
let result = unprocessed_entry.as_ref().unwrap().extract();
}); This could be mitigated by returning a suitable error when trying to process an already processed entry. Of course ideally the compiler should be able to prevent this from happening, and with the right type for Another caveat with the I could submit a PR with my Also I don't think thread safety is a concern here? There's also the additional concern of whether a faster route for listing archive contents is desired? As in should the |
Have you tried using the Personally I'm also more and more leaning more towards the FSM approach. I took a look into the WIP branch you mentioned and I see what you're doing but I believe we can do even better to prevent invalid usage. Pseudo code of what I had imagined the API to be like:
This way, we get rid of those What do you think? |
No, I haven't tried As for the pseudo code, I'm not seeing the benefits. To me it seems to only make iteration harder, since the iterator will keep moving around. Also won't those I was envisioning that the |
Currently, one operation is provided to rule all entries. i.e. the operation is set for an entire archive, when the RAR format can do better: it allows, to some extent, to provide different operations on an entry-to-entry basis, so one could extract some entries and decide to skip others.
One could also provide a different destination folder to extract for each entry. This would take some burden off the struct, as well, as it wouldn't need to keep a record of these things.
Currently, when opening an archive,
RAR
needs only two pieces of information:filename
- the path to the archive.OpenMode
- this can be eitherLIST
orEXTRACT
(orLIST_SPLIT
which is likeLIST
but behaves differently for multipart archives). This, in essence, prepares the archive for a set of operations. You cannotextract
from an archive which was opened inLIST
mode, for example.My idea is to return an
Entry
in the iterator, which is produced by the nativeread_header
call. The problem, why normal iterators won't work, is because the Iterator needs to return owned values, it cannot return a borrowed value to an interior field.That would separate the
Archive
and theEntry
, however, they cannot be separate, because the call sequence on aHandle
has some restrictions, e.g. callingRARReadHeader
after a failedRARProcessFile
is illegal.Instead I've been investigating the
streaming_iterator
crate. I'm currently struggling with the interface, since it does not allow mutable reference to be returned innext
so I cannot mutateEntry
and thus track whether it has been processed by the user or not. I need this information however in order to know whether to callRARProcessFile(Operation::Skip)
on the handle, because calling it when the file has already been processed leads to weird behavior and not calling it leads to an error in the nextRARReadHeader
step.The text was updated successfully, but these errors were encountered: