Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Unzip file from resources

Unzip file from resources

Scheduled Pinned Locked Moved C#
question
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JCompier
    wrote on last edited by
    #1

    Hello all i know how can i unzip file from hardisk but how can i Unzip file from resources directly without copy it to outside of resources first

    OriginalGriffO D J 3 Replies Last reply
    0
    • J JCompier

      Hello all i know how can i unzip file from hardisk but how can i Unzip file from resources directly without copy it to outside of resources first

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Please don't repost if your question does not appear immediately: all of these went to moderation and required a human being to review them for publication. In order to prevent you being kicked off as a spammer, all four had to be accepted, and then I have to clean up the spares. Have a little patience, please! I'll delete the other three versions.

      Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • J JCompier

        Hello all i know how can i unzip file from hardisk but how can i Unzip file from resources directly without copy it to outside of resources first

        D Offline
        D Offline
        Daniel Pfeffer
        wrote on last edited by
        #3

        Most compression libraries treat the file to be decompressed as a stream of bytes. If you have the source code for the library, you can modify it as follows: 1. Load the resource (instead of opening the file) 2. Convert all reads from the file to memcpy() operations 3. Discard the resource (instead of closing the file) In a well-written library, you shouldn't have too many places that require modification.

        Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

        J 1 Reply Last reply
        0
        • D Daniel Pfeffer

          Most compression libraries treat the file to be decompressed as a stream of bytes. If you have the source code for the library, you can modify it as follows: 1. Load the resource (instead of opening the file) 2. Convert all reads from the file to memcpy() operations 3. Discard the resource (instead of closing the file) In a well-written library, you shouldn't have too many places that require modification.

          Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

          J Offline
          J Offline
          JCompiler
          wrote on last edited by
          #4

          How can i open the file directly from resources i havnt no idea

          Richard DeemingR 1 Reply Last reply
          0
          • J JCompiler

            How can i open the file directly from resources i havnt no idea

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Assembly.GetManifestResourceStream[^] will give you a Stream which you can use to read the content of an embedded resource. Why have you created two different accounts to post the same question? :confused: JCompiler - Professional Profile[^] JCompier - Professional Profile[^]


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            J 2 Replies Last reply
            0
            • Richard DeemingR Richard Deeming

              Assembly.GetManifestResourceStream[^] will give you a Stream which you can use to read the content of an embedded resource. Why have you created two different accounts to post the same question? :confused: JCompiler - Professional Profile[^] JCompier - Professional Profile[^]


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              J Offline
              J Offline
              JCompiler
              wrote on last edited by
              #6

              I dont know i created just one but i was have an erreo on confirmision . I dont know where the problem

              1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                Assembly.GetManifestResourceStream[^] will give you a Stream which you can use to read the content of an embedded resource. Why have you created two different accounts to post the same question? :confused: JCompiler - Professional Profile[^] JCompier - Professional Profile[^]


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                J Offline
                J Offline
                JCompiler
                wrote on last edited by
                #7

                yes iam now using this code

                        string resource = "Installer.Resources.myFile.zip";
                        System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
                        Stream resFilestream = a.GetManifestResourceStream(resource);
                

                but i can't use the

                ZipArchive archive = ZipFile.OpenRead(resFilestream);

                becouse the OpenRead Function need the path of physical path on hard disk what can i do to can full archive with myFile.zip to can i read it and extract any file contains in this archive

                Richard DeemingR 1 Reply Last reply
                0
                • J JCompiler

                  yes iam now using this code

                          string resource = "Installer.Resources.myFile.zip";
                          System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
                          Stream resFilestream = a.GetManifestResourceStream(resource);
                  

                  but i can't use the

                  ZipArchive archive = ZipFile.OpenRead(resFilestream);

                  becouse the OpenRead Function need the path of physical path on hard disk what can i do to can full archive with myFile.zip to can i read it and extract any file contains in this archive

                  Richard DeemingR Offline
                  Richard DeemingR Offline
                  Richard Deeming
                  wrote on last edited by
                  #8

                  ZipArchive archive = new ZipArchive(resFilestream);

                  ZipArchive Class (System.IO.Compression) | Microsoft Docs[^]


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  1 Reply Last reply
                  0
                  • J JCompier

                    Hello all i know how can i unzip file from hardisk but how can i Unzip file from resources directly without copy it to outside of resources first

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #9

                    JCompier wrote:

                    Unzip file from resources directly without copy it to outside of resources first

                    Make sure of course both of the following are true - You realize that it would still be in memory and memory can be swapped to the hard drive. I only bring this up because I have seen requests before involving military work where the content could not be stored under any circumstances. - You determine that the source (zip file) will never be 'big'. So a 1k zip file is ok but if it is possible and you do not specifically code a check for this, that the file is 100 meg or 1 gig, then unzipping in memory is going to be a problem.

                    Richard DeemingR 1 Reply Last reply
                    0
                    • J jschell

                      JCompier wrote:

                      Unzip file from resources directly without copy it to outside of resources first

                      Make sure of course both of the following are true - You realize that it would still be in memory and memory can be swapped to the hard drive. I only bring this up because I have seen requests before involving military work where the content could not be stored under any circumstances. - You determine that the source (zip file) will never be 'big'. So a 1k zip file is ok but if it is possible and you do not specifically code a check for this, that the file is 100 meg or 1 gig, then unzipping in memory is going to be a problem.

                      Richard DeemingR Offline
                      Richard DeemingR Offline
                      Richard Deeming
                      wrote on last edited by
                      #10

                      jschell wrote:

                      So a 1k zip file is ok but if it is possible and you do not specifically code a check for this, that the file is 100 meg or 1 gig, then unzipping in memory is going to be a problem.

                      If the file could be modified by a malicious actor, even a small zip file could be a problem:

                      Zip bomb - Wikipedia[^]:

                      One example of a zip bomb is the file 42.zip, which is a zip file consisting of 42 kilobytes of compressed data, containing five layers of nested zip files in sets of 16, each bottom layer archive containing a 4.3-gigabyte file for a total of 4.5 petabytes of uncompressed data.


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups