How add png image to zip file using std.zip?

JN 666total at wp.pl
Sun Feb 21 18:10:43 UTC 2021


On Sunday, 21 February 2021 at 17:17:56 UTC, Marcone wrote:
> 	ZipArchive zip = new ZipArchive();
> 	std.file.write("foo.zip", zip.build());
>
> 	ArchiveMember f = new ArchiveMember();
> 	f.name = "Wallpaper_001.png";
> 	
> 	zip.addMember(f);
> 	std.file.write("foo.zip", zip.build());
>
> File is added with file size 0.
> How can I use expandedData for add images files? Or what I use 
> for it?

expandedData should hold the contents of the uncompressed file, 
as byte array. So something like:

f.name = "Wallpaper_001.png";
f.expandedData = cast(ubyte[])std.file.read("Wallpaper_001.png");

should work. f.name = "Wallpaper_001.png" only says "create a 
file named Wallpaper_001.png inside the zip". It doesn't say "put 
the Wallpaper_001.png file into the zip".


More information about the Digitalmars-d-learn mailing list