# PhysicsFS and writing to zip archive

This topic is 4504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello! I've been trying out PhysicsFS and it seems like a really neat library, however it seems that there isn't much information/examples/tutorials out there about it. Or, my googleskills are worthless :( I've been able to read from zip archives with the help of the very minimalistic tutorial on http://www.icculus.org/physfs/ But I cant write back to a file if my life depended on it. The PHYSFS_write() function returns what I expect it to, but the file within the zip stays the same. Is writing back to a zip even possible? Regards /ixi [Edited by - ixilom on September 19, 2006 6:43:42 PM]

##### Share on other sites
Make sure you open the file with PHYSFS_openWrite as opposed to PHYSFS_openRead.

##### Share on other sites
Of course I used PHYSFS_openWrite =)

Here are the steps I used, sorta in pseudocode (dont have my source available atm)

PHYSFS_init(NULL);
PHYSFS_setWriteDir(PHYSFS_getBaseDir());
PHYSFS_file *fp = PHYSFS_openWrite("some_file_in_zip.bin");
PHYSFS_write(fp,myStruct,sizeof(struct myStruct),1);
PHYSFS_close(fp);
PHYSFS_deinit();

All of the above functions return whats expected, in other words, my file in the zip should be updated .. but nope.

Any suggestions?

##### Share on other sites
Can you write a basic string? I'd be interest to know what's wrong with it....

##### Share on other sites
Okay, I wrote a simple test, a zipfile called test.zip containing test.txt. That textfile contains "change me".

Then I run this piece of code
PHYSFS_init(NULL);if(PHYSFS_addToSearchPath("test.zip",1)) {	if(PHYSFS_setWriteDir(PHYSFS_getBaseDir())) {		PHYSFS_file *fp = PHYSFS_openWrite("test.txt");		if(fp) {			int count = PHYSFS_write(fp,"hello",5,1);			if(PHYSFS_flush(fp)) {				if(count==1) {					int z = 0; // just something I can setup a breakpoint on to see if the code reached this far				}			}			PHYSFS_close(fp);		}	}}

But alas, the test.txt in the zip stays the same :(
Even added PHYSFS_flush() there just in case, but nothing happened.

Maybe something screwed up when I built the dll/lib in MSVC .NET .. I know I had to hack it some to get it to compile. Replaced some _alloca to alloca. _alloca is alloca on WIN32, just a #define that didn't want to work as it should, but still... its driving me crazy >:|

*bump*

##### Share on other sites
Are you sure that PhysFS supports the feature of writing to zipfiles? last time i checked, only readings were available

##### Share on other sites
Hi Wixner!

Thanks for the answer. In the original post I wrote:

"Is writing back to a zip even possible?"

I couldn't find anything that said you cant, only that PhysicsFS supports zip archives. Thanks to you I now know that its not possible =)

##### Share on other sites
I dont think you can write to zip files, in fact im almost sure you can't, you can only read.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 17
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634094
• Total Posts
3015498
×