Extract file content into string without creating a flie

Find quick help here to get you started with Hollywood
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Extract file content into string without creating a flie

Post by Flinx »

Interesting. Maybe the behavior is actually only half a bug.
I looked up the problem in the manual again, but it doesn't seem to be mentioned directly.
However, section 7.9 (Loaders and adapters) describes the process of how loaders are used (Hollywood will ask all plugins whether they want to handle the file).
That explains the effect to some extent, but I would like to see a comment in the manual or a more informative error message.
amyren
Posts: 410
Joined: Thu May 02, 2019 11:53 am

Re: Extract file content into string without creating a flie

Post by amyren »

It seems DeleteFile does have the ability to use the zip plugin, just not via InstallAdapter. Adapter = "zip" works
Here in this example there is no zip.defaultpassword set, and no password in the argument of DeleteFile, but it still is able to access the archive and delete files within it. The password must be left in memory and used by the zip plugin also for DeleteFile. If running a script with only the DeleteFile command I am not able to delete files in the archive.

Code: Select all

@REQUIRE "zip", {Link = True}
secretfile$ = DefineVirtualFileFromString("This\nis\nthe\nvery\nsecret\nmessage", "secretmessage.data")
secretfile2$ = DefineVirtualFileFromString("This\nis\nthe\nsecond\nsecret\nmessage", "secretmessage2.data")
zip.OpenArchive(1, "secret.zip", #MODE_WRITE)
zip.AddFile(1, secretfile$, {Encryption = #ZIP_EM_AES_128, Password = "test1234"})
zip.AddFile(1, secretfile2$, {Encryption = #ZIP_EM_AES_128, Password = "test1234"})
zip.CloseArchive(1)
UndefineVirtualStringFile(secretfile$)
UndefineVirtualStringFile(secretfile2$)
NPrint("ZIP created with 2 files")

OpenFile(1, "secret.zip/secretmessage.data", #MODE_READ, {Adapter="zip", UserTags = {Password = "test1234"}})
	While Not Eof(1) Do NPrint(ReadLine(1))
CloseFile(1)
NPrint("")
OpenFile(1, "secret.zip/secretmessage2.data", #MODE_READ, {Adapter="zip", UserTags = {Password = "test1234"}})
	While Not Eof(1) Do NPrint(ReadLine(1))
CloseFile(1)

WaitLeftMouse
DeleteFile("secret.zip/secretmessage.data", {Adapter="zip"})
off topic: I was not aware of this thing about zip archives that you could have both encrypyted and unencrypted files in the same archive.
User avatar
airsoftsoftwair
Posts: 5830
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Extract file content into string without creating a flie

Post by airsoftsoftwair »

amyren wrote: Fri Oct 17, 2025 5:31 pm It seems DeleteFile does have the ability to use the zip plugin, just not via InstallAdapter.
Yup, as documented in the manual:
Note that it's mandatory to pass the Adapter tag to DeleteFile() because zip.hwp doesn't install a filesystem adapter even when setting the InstallAdapter tag to True (see above). Zip.hwp's filesystem adapter is only accessible by directly passing it to a Hollywood function in the Adapter tag
(source)

The reason why this code doesn't work...

Code: Select all

DeleteFile("serverconfig.zip",{force=True})
...is the following: DeleteFile() supports the deletion of files *and* directories. So the first thing DeleteFile() does is to check if what was passed to it is a file or a directory. Now what happens here is this: When "InstallAdapter" is TRUE, the zip.hwp adapter kicks in and tells DeleteFile() that serverconfig.zip is a directory because that's the way the zip plugin exposes zip archives to Hollywood's file system handler. So what DeleteFile() tries to do next is iterating through all files in serverconfig.zip and deleting them but this won't work because deleting files from zip archives is done through the filesystem adapter of zip.hwp but this is only available if you pass "zip" in the "Adapter" tag. Then it will work but of course it's unnecessary overhead because it will delete files one by one from inside the zip archive so as you've already found out just passing "Inbuilt" to "Adapter" when calling DeleteFile() will just skip the adapter installed by the zip plugin and just delete the file as you probably expected it.

I agree that all this is somewhat confusing but the file system handler stuff is quite complex and can do lots of magic but admittedly it sometimes also overcomplicates very simple things ;)
Post Reply