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

Marcone marcone at email.com
Mon Feb 22 09:43:12 UTC 2021


On Sunday, 21 February 2021 at 18:10:43 UTC, JN wrote:
> 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".

Very good! Work very well. I was trying using rawRead. Now work 
fine.


More information about the Digitalmars-d-learn mailing list