-1

I need to extract a zip file in RAM with my python script. I have searched about Ramdisk in linux and I have some experiences in using Ramdisk. It's Ok for me but it has a big problem. Everyone who access my directories can see the unzipped file that I extracted them there (in Mounted Ramdisk), I need to access those unzipped files but it is necessary that only my python script can read and write file in RAM. Do you have a better way for my program? Or a solution for this problem? Thanks.

edit: It has to be possible to interact with extracted files like normal files in a directory. not just open and read them.

Amirhosein
  • 11
  • 1
  • 4
    Possible duplicate of [python: Open file from zip without temporary extracting it](https://stackoverflow.com/questions/19371860/python-open-file-from-zip-without-temporary-extracting-it) – Joe Nov 22 '18 at 12:18
  • 1
    The only way you would be able to "interact" with the extracted files outside of the python program is if they're placed on a ramdisk. Python does not come with software to create one. – martineau Nov 22 '18 at 12:35
  • I can run os commands by my python program to create RamDisk, but I want only my python script access those files. – Amirhosein Nov 22 '18 at 12:56

1 Answers1

0

I'd create a secure temporary directory under /dev/shm and then extract the zip file into that. Due to its unpredictable name and tight permissions, only your user will be able to interact with it.

https://docs.python.org/3/library/tempfile.html#tempfile.TemporaryDirectory

grifferz
  • 181
  • 8