Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IO::File -> Filehandles -> Archive::Zip

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

This probably is going to sound like a stupid question but here goes.

When I open a filehandle or new IO::File object, does it create a physical file on the hard drive or a virtual file in memory.

I'm using Archive::Zip and was considering some way of creating the zip archive in memory and printing to STDOUT, I've tried a few of the 'filehandle' examples in Archive::Zip , but I get an error about 'bad file descriptor' if I just create a new IO::File object without a filename.

Is it possible to create a filehandle that is in memory not on the hard drive and then print to it? So I can then output the file in memory to STDOUT (the browser).

I've currently got it working by creating a temp zip file on the fly, then opening it and printing to STDOUT and then deleting the temp file when finished.

What is the best way and is trying to store a 100MB zip file in memory to print to STDOUT going to hog the webserver resources once a few people start downloading?

Is creating temporary zip files the 'best practice' method of doing this?

Thanks,

1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

MIME::Lite TLS Email Encryption - Perl v0.02 beta
 
I should add I found this to be a very good solution for some of my problems. I am creating data in a file to bulk load into mysql, so I was reading a file, writing it to another file, reading that file into SQL. A lot of disk read/writes.

I moved it to read a file, write to /dev/shm, and read that /dev/shm file into SQL.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Cool, I think the server in question is Linux/FreeBSD , so can you provide me an example of where you create the file/filehandle pointing to /dev/shm so I can test please.

I assume I need to ensure these files are deleted otherwise it will fill up memory, and s i have shared hosting, would cause me to get penalised for resource abuse if not carefull.

Guidance on its use and best practices is appreciated.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

MIME::Lite TLS Email Encryption - Perl v0.02 beta
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top