adamhathcock / sharpcompress

SharpCompress is a fully managed C# library to deal with many compression types and formats.
MIT License
2.22k stars 476 forks source link

[Question] Multi-volume rar streaming #776

Open Xodaru opened 8 months ago

Xodaru commented 8 months ago

In a presentation you did at Dot Net Sheff back in 2018 you mentioned one of the use cases of SharpCompress was to mount ISOs as an image when they are spanned across multiple RAR files.

I am trying to wrap my head around this to do something similar but struggling to read a file that spans multiple rar files. Do you have an example on how this was achieved?

Part of the problem I have is the stream is not seek'able as with my use case I know exactly what offset of the file I want to start extracting from. I can only send data when its requested, not in a continuous stream thus I have to work with offsets. I'm guessing an ISO mount implementation of this would be somewhat similar.

adamhathcock commented 8 months ago

The RarReader tests do it: https://github.com/adamhathcock/sharpcompress/blob/master/tests/SharpCompress.Test/Rar/RarReaderTests.cs#L63

Xodaru commented 8 months ago

Hi adamhathcock, Thanks very much for that

Apologies for my stupid question, but I dont understand how this can achieve streaming part of the archive on request. It seems to just extract the whole file and write it to disk? Basically like a normal extraction.

I want to be able to read a specific file in 1MB chunks (the offset and size to extract are parameters to the main processing method) as the data will be sent across a bus. Each time this method is called the offset to start at is updated as its the bus that decides what it needs to get.

adamhathcock commented 8 months ago

you have to read all bytes in a forward-only scenario. There is no seeking. Once you know the entry then you just deal with that stream

If you want to deal with seeking then use the Archive interface with your pieces: https://github.com/adamhathcock/sharpcompress/blob/master/tests/SharpCompress.Test/Rar/RarArchiveTests.cs#L253