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
  1. Home
  2. General Programming
  3. C#
  4. File header processing... [modified]

File header processing... [modified]

Scheduled Pinned Locked Moved C#
cryptographyhelpquestion
11 Posts 3 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.
  • N Offline
    N Offline
    natsuyaki
    wrote on last edited by
    #1

    Name Size Value Desciption HEADER 4 bytes 0x04036b2e Mark this file as readable FILE_LEN 4 bytes Int32 Mark the length of FILE block FILE runtime byte[] The file's original name HASH 16 bytes byte[] Hash code of the data(header excluded) This is a simple header of a compressed file I'm developing. Each time a file is required to be processed, the program will firstly check the header. If passed, compress the file and add header to it. The problem is, I have to firstly read the source file and create the output file, and then compress it by using a third party method(the method will automatically close the input and output stream X| ), then open the output file again, read it out to a buffer, write the header, and finally write the data in the buffer to the output file. It's very inefficient:~. Is there any more efficient way to do this? Thanks in advance...

    modified on Sunday, May 11, 2008 4:52 AM

    L 1 Reply Last reply
    0
    • N natsuyaki

      Name Size Value Desciption HEADER 4 bytes 0x04036b2e Mark this file as readable FILE_LEN 4 bytes Int32 Mark the length of FILE block FILE runtime byte[] The file's original name HASH 16 bytes byte[] Hash code of the data(header excluded) This is a simple header of a compressed file I'm developing. Each time a file is required to be processed, the program will firstly check the header. If passed, compress the file and add header to it. The problem is, I have to firstly read the source file and create the output file, and then compress it by using a third party method(the method will automatically close the input and output stream X| ), then open the output file again, read it out to a buffer, write the header, and finally write the data in the buffer to the output file. It's very inefficient:~. Is there any more efficient way to do this? Thanks in advance...

      modified on Sunday, May 11, 2008 4:52 AM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Does the method supplied for compression offer the chance to compress it in memory - ie pass it a stream that points to memory? http://msdn.microsoft.com/en-us/library/336wast5.aspx. If so you can use a StringReader/Writer if you wanted to work with strings or any other type of stream reader writer that takes your fancy. This should be faster than writing to disk then re-writing to disk with a header.

      At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan

      N 1 Reply Last reply
      0
      • L Lost User

        Does the method supplied for compression offer the chance to compress it in memory - ie pass it a stream that points to memory? http://msdn.microsoft.com/en-us/library/336wast5.aspx. If so you can use a StringReader/Writer if you wanted to work with strings or any other type of stream reader writer that takes your fancy. This should be faster than writing to disk then re-writing to disk with a header.

        At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan

        N Offline
        N Offline
        natsuyaki
        wrote on last edited by
        #3

        Yes. It's defined as this: public void Compress(Stream source, Stream target) But all the stream I passed to it will be closed. If I use memory stream, I won't be able to retrieve the compressed data.

        L 1 Reply Last reply
        0
        • N natsuyaki

          Yes. It's defined as this: public void Compress(Stream source, Stream target) But all the stream I passed to it will be closed. If I use memory stream, I won't be able to retrieve the compressed data.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If the stream points to a string then can you not use the string once the stream is closed and compressed. Then add the header added then write it to a file?

          At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan

          N 1 Reply Last reply
          0
          • L Lost User

            If the stream points to a string then can you not use the string once the stream is closed and compressed. Then add the header added then write it to a file?

            At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan

            N Offline
            N Offline
            natsuyaki
            wrote on last edited by
            #5

            Thanx Dan. I'll have a try.

            B 1 Reply Last reply
            0
            • N natsuyaki

              Thanx Dan. I'll have a try.

              B Offline
              B Offline
              boblaw99
              wrote on last edited by
              #6

              If the header has been generated before compressing, before pass the target stream into the compress method you can try writing the header into the target stream and set the stream's position at the end. My english is very pool, i help i have said clearly.

              N 1 Reply Last reply
              0
              • B boblaw99

                If the header has been generated before compressing, before pass the target stream into the compress method you can try writing the header into the target stream and set the stream's position at the end. My english is very pool, i help i have said clearly.

                N Offline
                N Offline
                natsuyaki
                wrote on last edited by
                #7

                thanx boblaw. But the HASH is the hash code of the compressed data.

                B 1 Reply Last reply
                0
                • N natsuyaki

                  thanx boblaw. But the HASH is the hash code of the compressed data.

                  B Offline
                  B Offline
                  boblaw99
                  wrote on last edited by
                  #8

                  Your hash code is fixed in 16 bytes. Firstly you can wirte 16 empty bytes into to stream before compressing. After you get the HASH, seek the stream'position at the first byte of 16 bytes and write hash code into it.

                  N 1 Reply Last reply
                  0
                  • B boblaw99

                    Your hash code is fixed in 16 bytes. Firstly you can wirte 16 empty bytes into to stream before compressing. After you get the HASH, seek the stream'position at the first byte of 16 bytes and write hash code into it.

                    N Offline
                    N Offline
                    natsuyaki
                    wrote on last edited by
                    #9

                    Thanks a lot. But doing this will cause the header be compressed with the data.

                    B 1 Reply Last reply
                    0
                    • N natsuyaki

                      Thanks a lot. But doing this will cause the header be compressed with the data.

                      B Offline
                      B Offline
                      boblaw99
                      wrote on last edited by
                      #10

                      My mean is you can write empty bytes into target stream before compressing, not source stream.

                      N 1 Reply Last reply
                      0
                      • B boblaw99

                        My mean is you can write empty bytes into target stream before compressing, not source stream.

                        N Offline
                        N Offline
                        natsuyaki
                        wrote on last edited by
                        #11

                        Sorry for misunderstanding.... ;P I'll check it out whether the method will seek to the Begin and overwrite my header...

                        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