473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3916
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dennis Hotson | last post by:
Hi, I'm trying to write a function that adds a file-like-object to a compressed tarfile... eg ".tar.gz" or ".tar.bz2" I've had a look at the tarfile module but the append mode doesn't support...
1
by: Ron Clarke | last post by:
Does anyone know how to get the compressed size of a file on disk? FileInfo.Length gives the uncompressed size of a file, but I need to find the amount of disk space taken up by files in compressed...
4
by: Pavel | last post by:
Hello. I am trying to make a folder compressed and failing miserably. Below are three ways that I tried to make it compressed, all of them compile and run w/o any problems, but the folder is...
2
by: dineshbajaj | last post by:
Hi Everybody, I need to split an image file(*.jpeg) programmatically to nine or more equal parts. Since, the code is meant to run on Windows Pocket PC 2002, I can only use methods supported...
3
by: Justin Busch | last post by:
I thought I saw an article online about programmatically using the Send To Compressed (zipped) Folder function in VB, however that page no longer exists. Does anyone have details on how this is...
8
by: robert | last post by:
Hello, I want to put (incrementally) changed/new files from a big file tree "directly,compressed and password-only-encrypted" to a remote backup server incrementally via FTP,SFTP or DAV.... At...
1
by: KJ | last post by:
I am using the System.Compression.GZipStream class, and I noticed that in certain cases, the resultant compressed file is actually larger than the original. This is almost a constant when...
2
by: mravichandran | last post by:
dear Readers, i will be downloading a zip file from the intranet website programmatically and i would like to process some of the files inside them before the user can save it. we have a lot of...
2
by: Author | last post by:
I am exploring the DeflateStream class as a practice. I thought it is fun to compress a text file and write it to a disk file. So I created the following method. If you don't bother reading the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.