How to split a big file ?
How to split a big file ?
- Subject: How to split a big file ?
- From: Michaƫl Parrot <email@hidden>
- Date: Mon, 20 Mar 2006 17:30:38 +0100
Hi,
I would like split file with 10MB (or more) segment.
But, when split 250MB or more datas, OS X swap and use more RAM.
Also, I try it with split command.
How I can reduce this memory usage ?
Thanks for all info about this.
Michael Parrot
NSInputStream *R=[[NSInputStream alloc] initWithFileAtPath:path];
[R open];
int i=0;
unsigned long long offset=0;
unsigned int r,dec=(10*1024*1024);
void *data=(void*)malloc(dec);
offset=dec;
while (r=[R read:data maxLength:dec])
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
NSString *pFile=[path stringByAppendingFormat:@"%d",++i];
offset+=dec;
// NSOutputStream...
NSOutputStream *W=[[NSOutputStream alloc] initToFileAtPath:pFile
append:NO];
[W open];
[W write:data maxLength:r];
[W close];
[W release];
/*
// NSFileHandle...
int Wd=open ([pFile fileSystemRepresentation],O_WRONLY | O_CREAT |
O_EXCL, S_IREAD | S_IWRITE);
NSData *theData=[[NSData alloc] initWithBytes:data length:r];
NSFileHandle *W=[[NSFileHandle alloc] initWithFileDescriptor:Wd
closeOnDealloc:YES];
[W seekToFileOffset:0];
[W writeData:theData];
[W synchronizeFile];
[W closeFile];
[theData release];
[W release];
*/
/*
// FWrite
FILE *W=fopen([pFile fileSystemRepresentation],"w");
fwrite(data,1,r,W);
fclose(W);
*/
/* // NSData
NSData *W=[[NSData alloc] initWithBytes:data length:r];
[W writeToFile:pFile atomically:NO];
[W release];
*/
NSLog(@"write r:%d - i:%d",r,i);
[pool release];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden