Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unzip archive in Dlang

I’m trying to unpack zip archive in Dlang, but all methods what im tried isnt work.

I’m tried to:
auto archive = "/var/cache/dpm/packages/"~packagename~"/"~packagename~".zip"; auto zip = new ZipArchive(read(archive)); writeln(read(archive));
Excepted to get what archive contains, but get only many numbers.(You can see it on screenshot)
What is happens
After this, i tried to readText instead of read because i see something like this when tried to read file with read and not readText, but it gives me error:
tf.d(1556): Invalid UTF-8 sequence (at index 1)
Where is my error?
Thanks for your help!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

What you are seeing is the default output of a ubyte[] array. It’s a list of bytes, printed in decimal form.

read(archive) gives you the ubytes in the file. Nothing else. You are reading the file twice, the first time creating an archive out of it (which succeeds), and the second time reading it into a ubyte[] array and printing that.

If you want the zip contents, you have to use the ZipArchive api to do it. Looks like that would be zip.directory["fileToExtract"].expandedData

See the documentation for ZipArchive, and an example how to use it here: https://dlang.org/phobos/std_zip.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading