Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Aspect13 · Jan 14, 2019 at 08:46 PM · filescompressionfilestreamdecompresscompress

Decompress a file with code.

I literally tried everything. I'm a beginner so I don't know stuff like that. I know there is a documentation about GZipStream etc. and I read it, really wanted to understand it and even I used the code but I could not maybe understand it or it does not work, I guess the first option works out here. I also tried 2 of the GitHub projects. Nothing worked. I tried Zip and Unzip and Unity Archiver. Maybe I am doing something wrong but I really need to do it. I only want to decompress some new files and delete the old ones. Something like an updater system for my game. I'm downloading files from FTP server, then I want to decompress them and delete the old ones. I just need the decompression to be done. Please help. I really care about that.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by xxmariofer · Jan 14, 2019 at 08:54 PM

There are a lot of assets in the asset store for extracting zip, i would suggest using simple Zip

https://assetstore.unity.com/packages/tools/simple-zip-81871

what kind of error or problems are you having? i once had a similar issue and was trying to decompress the file before making sure the file was 100% downloaded. If you give me extra info like error or code i can maybe give you a better approach

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Aspect13 · Jan 14, 2019 at 09:36 PM

I can't add comment to your reply for whatever reason :/ Posting it as an answer also.

The asset can only decompress text so it won't work. Well, in the Unity Archiver on GitHub was broken script I think, couldn't fix it. In the Zip and Unzip also on GitHub. I couldn't figure out how to use it to be honest. The other errors are with GZipStream, like the name of this and this is wrong or something does not contain something, I added some namespaces but it was showing forever. Also my code for downloading is from a guy from Unity Forum. And by the way, I printed the progress of the download script and it was always -1. Here's the code:

 private byte[] downloadWithFTP(string ftpUrl, string savePath = "", string userName = "", string password = "")
 {
     FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(ftpUrl));
     //request.Proxy = null;
 
     request.UsePassive = true;
     request.UseBinary = true;
     request.KeepAlive = true;
 
     //If username or password is NOT null then use Credential
     if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
     {
         request.Credentials = new NetworkCredential(userName, password);
     }
 
     request.Method = WebRequestMethods.Ftp.DownloadFile;
 
     //If savePath is NOT null, we want to save the file to path
     //If path is null, we just want to return the file as array
     if (!string.IsNullOrEmpty(savePath))
     {
         downloadAndSave(request.GetResponse(), savePath);
         return null;
     }
     else
     {
         return downloadAsbyteArray(request.GetResponse());
     }
 }
 
 byte[] downloadAsbyteArray(WebResponse request)
 {
     using (Stream input = request.GetResponseStream())
     {
         byte[] buffer = new byte[16 * 1024];
         using (MemoryStream ms = new MemoryStream())
         {
             int read;
             while (input.CanRead && (read = input.Read(buffer, 0, buffer.Length)) > 0)
             {
                 ms.Write(buffer, 0, read);
             }
             return ms.ToArray();
         }
     }
 }
 
 void downloadAndSave(WebResponse request, string savePath)
 {
     Stream reader = request.GetResponseStream();
 
     //Create Directory if it does not exist
     if (!Directory.Exists(Path.GetDirectoryName(savePath)))
     {
         Directory.CreateDirectory(Path.GetDirectoryName(savePath));
     }
 
     FileStream fileStream = new FileStream(savePath, FileMode.Create);
 
 
     int bytesRead = 0;
     byte[] buffer = new byte[2048];
 
     while (true)
     {
         bytesRead = reader.Read(buffer, 0, buffer.Length);
 
         if (bytesRead == 0)
             break;
 
         fileStream.Write(buffer, 0, bytesRead);
     }
     fileStream.Close();
 }

and this is how I use it:

 string path = Path.Combine(Application.persistentDataPath, "FTP Files");
 path = Path.Combine(path, "data.png");
 downloadWithFTP("ftp://yourUrl.com/yourFile", path, "UserName", "Password");

The original thread is here: https://stackoverflow.com/questions/43411525/download-files-via-ftp-on-android

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · Jan 15, 2019 at 08:36 AM 0
Share

Hello @Aspect13 i can share some code if you need it if the problem persist but use this asset, was the one i used and workds easy and fine.

https://forum.unity.com/threads/unizip-free-zipper-unzipper.220589/

avatar image Aspect13 xxmariofer · Jan 15, 2019 at 09:12 AM 0
Share

I used it already. Was not working though. I will try again and see if it works and if no what errors it gives.

avatar image xxmariofer Aspect13 · Jan 15, 2019 at 12:46 PM 0
Share

Then use the WWW class, it was deprecated but solved me errors when unity api couldnt. your code looks fine sorry i cant help you more.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

98 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keep file structure on build. 1 Answer

Unity 4096*4096 Texture Compression 1 Answer

Problems with compression of images for ios 0 Answers

Writing to a file which i just created. 1 Answer

Decoding a 16 bit 1 channel png 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges