469,362 Members | 2,611 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

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

Oct 26 '07 #1
6 3682
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

Oct 26 '07 #2
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.
Oct 26 '07 #3
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.
Oct 26 '07 #4
On Fri, 26 Oct 2007 06:46:33 -0700, Brian Roisentul
<br************@hotmail.comwrote:
>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 programmatically
create a spanned archive

--
http://bytes.thinkersroom.com
Oct 26 '07 #5
On 26 oct, 18:12, "Rad [Visual C# MVP]" <r...@nospam.comwrote:
On Fri, 26 Oct 2007 06:46:33 -0700, Brian Roisentul

<brianroisen...@hotmail.comwrote:
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 programmatically
create a spanned archive

--http://bytes.thinkersroom.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

Oct 29 '07 #6
On 29 oct, 09:47, Brian Roisentul <brianroisen...@hotmail.comwrote:
On 26 oct, 18:12, "Rad [Visual C# MVP]" <r...@nospam.comwrote:


On Fri, 26 Oct 2007 06:46:33 -0700, Brian Roisentul
<brianroisen...@hotmail.comwrote:
>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 programmatically
create a spanned archive
--http://bytes.thinkersroom.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.ToString() );

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.ToString() ) : 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;
}
}

Oct 29 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Dennis Hotson | last post: by
1 post views Thread by Ron Clarke | last post: by
4 posts views Thread by Pavel | last post: by
2 posts views Thread by dineshbajaj | last post: by
3 posts views Thread by Justin Busch | last post: by
2 posts views Thread by Author | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.