473,807 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to split a compressed file programmaticall y?

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 3946
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.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.thinkersroom.com
Oct 26 '07 #5
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

Oct 29 '07 #6
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;
}
}

Oct 29 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
8847
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 compressed tarfiles... :( Any thoughts on what I can do to get around this?
1
1690
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 directories (Windows XP). Getting the "compressed" attribute is available, but how does one get the compressed size? Thanks in advance. -- Ron Clarke
4
14123
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 still not-compressed. (using NTFS, win2k) // some folder string path = @"C:\TEMP\";
2
7027
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 by the .Net Compact Framework. Thanks in Advance,
3
5971
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 possible? Justin Busch jbusch@ccac.edu
8
2783
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 best within a closed algorithm inside Python without extra shell tools. (The method should work with any protocol which allows somehow read, write & seek to a remote file.) On the server and the transmission line there should never be...
1
3309
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 compressing already-compressed formats such as jpeg. Another less-consistent example of this behavior is found in the case of compressing TIFFs, wherein some files end up greatly compressed (the larger ones up to 93% compression ratio) and others end up...
2
3868
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 copies of winzip. winzip does not let me call their functions as COM or as .NET assemblies. I want to use the native compressed folder function present in the Windows XP OS to open the zip file and process them before the user can
2
2271
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 small code snippet, here is a summary of what I did: 1. Read the text content into a buffer through FileStream.Read. 2. Create a DeflateStream by wrapping up a MemoryStream. 3. Write the compressed data into the underline stream (the...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10113
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9195
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.