www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How add png image to zip file using std.zip?

reply Marcone <marcone email.com> writes:
	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?
Feb 21 2021
parent reply JN <666total wp.pl> writes:
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".
Feb 21 2021
parent Marcone <marcone email.com> writes:
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.
Feb 22 2021