Asked by:
Read a json file from within a zip file

Question
-
User-183185495 posted
Is their a way in c# to read a file that is within a zip file I am developing an addon manager in .net for msfs and each add on has a maanifset.json included inside their zip files.
Is there a way to discover that file within the zip file itself without unpacking it and deserlize its contents for example the file strcuture of the add on would look like below.
Please note : I wish to read the file either from a url or disk without extracting it to a tempory location same way an api would fetch the data.
{ "dependencies": [ { "name": "fs-base-propdefs", "package_version": "0.1.2" } ], "content_type": "AIRCRAFT", "title": "Savage Carbon", "manufacturer": "Zlin Aviation & Got Gravel", "creator": "Asobo Studio & Got Gravel", "package_version": "0.1.35", "minimum_game_version": "1.9.2", "release_notes": { "neutral": { "LastUpdate": "", "OlderHistory": "" } }, "total_package_size": "00000000000538203000" }
This would normally be a zip file for example gotgravel-savage-carbon.zip I would be uploading the zip file to the server or else reading it from an url. I want to extract the info in mainfest.json
Friday, January 1, 2021 8:23 PM
All replies
-
User-474980206 posted
Use the zip file archive library
https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive.entries?view=net-5.0
Friday, January 1, 2021 8:45 PM -
User-183185495 posted
This example is still extracting the zip file to some tempory location i want to read it frrom uncompressed zp file
Use the zip file archive library
https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive.entries?view=net-5.0
Friday, January 1, 2021 8:47 PM -
User-474980206 posted
You can use streams (memory) instead of files, read the zip as stream, then loop thru entries until you find json file, then stream the json file to a buffer or into a json reader.
Saturday, January 2, 2021 5:11 AM -
User-857013053 posted
You can follow this link for read a json file from within a zip file
Tuesday, January 5, 2021 3:54 AM