How to split a compressed file programmatically?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Roisentul

    #1

    How to split a compressed file programmatically?

    Hi everyone,

    I've been investigating for a while about this, but with no luck yet.

    Does anybody know a way to do it?

    Many thanks,

    Brian

  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: How to split a compressed file programmaticall y?

    Well,
    if you load a compressed file into a byte array, you can create two new byte
    arrays and store the first half of the original bytes in one, and the second
    half in the other, and then save them to the filesystem. Are you asking "how
    to do this?"
    -- Peter
    Recursion: see Recursion
    site: http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    BlogMetaFinder: http://www.blogmetafinder.com



    "Brian Roisentul" wrote:
    Hi everyone,
    >
    I've been investigating for a while about this, but with no luck yet.
    >
    Does anybody know a way to do it?
    >
    Many thanks,
    >
    Brian
    >
    >

    Comment

    • Brian Roisentul

      #3
      Re: How to split a compressed file programmaticall y?

      Thanks for your answer Peter.

      I'll explain a little bit what i'm trying to do, because maybe it can
      be done without zipping files.

      Basically, i have a big file(it's a SharePoint site's backup, *.fwp
      file) in one server, that is moved to a ftp folder every night, and
      downloaded from another pc. These tasks are run automatically by a c#
      process I made.

      The time of download is of about 3hs, so I thought splitting the file
      into pieces, and then downloading them using threading, will make this
      process quicker.

      I tried to split the file without zipping it, but when I merge it
      back, it doesn't seem to work. If you want I can paste my code here so
      you can see it, because maybe I did something wrong.


      Comment

      • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

        #4
        Re: How to split a compressed file programmaticall y?

        What I would probably do here is to use either Winzip or WinRar with a batch
        file (they have DOS companions that accept batch comands) with "Store only" -
        no-compression for speed, to split up the files. This .bat or .cmd file can
        be run on a scheduled basis through Task Scheduler.
        -- Peter
        Recursion: see Recursion
        site: http://www.eggheadcafe.com
        unBlog: http://petesbloggerama.blogspot.com
        BlogMetaFinder: http://www.blogmetafinder.com



        "Brian Roisentul" wrote:
        Thanks for your answer Peter.
        >
        I'll explain a little bit what i'm trying to do, because maybe it can
        be done without zipping files.
        >
        Basically, i have a big file(it's a SharePoint site's backup, *.fwp
        file) in one server, that is moved to a ftp folder every night, and
        downloaded from another pc. These tasks are run automatically by a c#
        process I made.
        >
        The time of download is of about 3hs, so I thought splitting the file
        into pieces, and then downloading them using threading, will make this
        process quicker.
        >
        I tried to split the file without zipping it, but when I merge it
        back, it doesn't seem to work. If you want I can paste my code here so
        you can see it, because maybe I did something wrong.
        >
        >
        >

        Comment

        • Rad [Visual C# MVP]

          #5
          Re: How to split a compressed file programmaticall y?

          On Fri, 26 Oct 2007 06:46:33 -0700, Brian Roisentul
          <brianroisentul @hotmail.comwro te:
          >Hi everyone,
          >
          >I've been investigating for a while about this, but with no luck yet.
          >
          >Does anybody know a way to do it?
          >
          >Many thanks,
          >
          >Brian
          Take a look at the 7zip SDK ... it may allow you to programmaticall y
          create a spanned archive

          --

          Comment

          • Brian Roisentul

            #6
            Re: How to split a compressed file programmaticall y?

            On 26 oct, 18:12, "Rad [Visual C# MVP]" <r...@nospam.co mwrote:
            On Fri, 26 Oct 2007 06:46:33 -0700, Brian Roisentul
            >
            <brianroisen... @hotmail.comwro te:
            Hi everyone,
            >
            I've been investigating for a while about this, but with no luck yet.
            >
            Does anybody know a way to do it?
            >
            Many thanks,
            >
            Brian
            >
            Take a look at the 7zip SDK ... it may allow you to programmaticall y
            create a spanned archive
            >
            --http://bytes.thinkersr oom.com
            I'll try this, thanks.

            But I just wanted to know something also...

            Spliting a file and then merging it back must work? Even with
            "complex" files' types?

            I'm asking this because I tried it with a ".txt" file and it worked,
            but then, when i tried with an excel file with vb code inside, when i
            opened it, it threw me a message like something was wrong, but then I
            could see the grid's content, but the vb code wasn't there any more.

            The file's size was the same than the original and all.

            Then, when i tried it with a SharePoint's backup file (*.fwp) and
            tried to restore a site through command line, i got an error saying
            the file was corrupted or something like that.

            Thanks again,

            Brian

            Comment

            • Brian Roisentul

              #7
              Re: How to split a compressed file programmaticall y?

              On 29 oct, 09:47, Brian Roisentul <brianroisen... @hotmail.comwro te:
              On 26 oct, 18:12, "Rad [Visual C# MVP]" <r...@nospam.co mwrote:
              >
              >
              >
              >
              >
              On Fri, 26 Oct 2007 06:46:33 -0700, Brian Roisentul
              >
              <brianroisen... @hotmail.comwro te:
              >Hi everyone,
              >
              >I've been investigating for a while about this, but with no luck yet.
              >
              >Does anybody know a way to do it?
              >
              >Many thanks,
              >
              >Brian
              >
              Take a look at the 7zip SDK ... it may allow you to programmaticall y
              create a spanned archive
              >
              --http://bytes.thinkersr oom.com
              >
              I'll try this, thanks.
              >
              But I just wanted to know something also...
              >
              Spliting a file and then merging it back must work? Even with
              "complex" files' types?
              >
              I'm asking this because I tried it with a ".txt" file and it worked,
              but then, when i tried with an excel file with vb code inside, when i
              opened it, it threw me a message like something was wrong, but then I
              could see the grid's content, but the vb code wasn't there any more.
              >
              The file's size was the same than the original and all.
              >
              Then, when i tried it with a SharePoint's backup file (*.fwp) and
              tried to restore a site through command line, i got an error saying
              the file was corrupted or something like that.
              >
              Thanks again,
              >
              Brian- Ocultar texto de la cita -
              >
              - Mostrar texto de la cita -
              BTW, this is my code, maybe i did something wrong:

              //Note: this.ext is a string property which represents the file's
              extension.
              /
              *************** *************** *************** *************** *************** *
              splitFile procedure
              *************** *************** *************** *************** *************** */
              private void splitFile( string path, string path_parts, long
              size_part )
              {
              long parts=0;

              try
              {
              using ( FileStream fs = new FileStream( path, FileMode.Open ) )
              {

              flength = fs.Length;

              parts = fs.Length / long.Parse( size_part.ToStr ing() );

              if ( parts 0 )
              {
              for ( int i = 0; i < parts; i++ )
              {
              string filename= Path.Combine( path_parts, "spfile" +
              i.ToString() + this.ext );

              using ( FileStream fsOut = new FileStream( filename,
              FileMode.Create ) )
              {
              byte[] arrBytes = new byte[ flength ];

              int offSet = ( int ) (size_part * i ) + ( ( i>0 ) ? 1 : 0 );
              int count = ( int ) size_part;

              int ret = fs.Read( arrBytes, offSet, count );

              fsOut.Write( arrBytes, offSet, count );

              arrBytes = null;
              }
              }
              }
              }
              }
              catch {
              throw;
              }
              }

              /
              *************** *************** *************** *************** *************** *
              buildFile procedure
              *************** *************** *************** *************** *************** */
              private void buildFile( string path_parts, long size_part, long
              flength, string path_out )
              {
              try
              {
              byte[] arrBytes=null;

              string filename_out= Path.Combine( path_out, "spfile_out " +
              this.ext );

              long parts = ( size_part != 0 ) ? flength /
              long.Parse( size_part.ToStr ing() ) : 0;

              byte[] arrBytes_out= new byte[ flength ];


              for ( int i = 0; i < parts; i++ )
              {
              string filename= Path.Combine( path_parts, "spfile" +
              i.ToString() + this.ext );

              using ( FileStream fs = new FileStream( filename,
              FileMode.Open ) )
              {
              arrBytes = new byte[ size_part ];//fs.Length

              int ret = fs.Read( arrBytes, 0, Convert.ToInt32 ( size_part ) );//
              fs.Length


              arrBytes.CopyTo ( arrBytes_out, i * size_part );
              }
              }

              using ( FileStream fsOut = new FileStream( filename_out,
              FileMode.Create ) )
              fsOut.Write( arrBytes_out, 0, Convert.ToInt32 ( flength ) );
              }
              catch( Exception ex )
              {
              throw;
              }
              }

              Comment

              Working...