From bc4cbdaaeb5d2ba51135edf6d793932536e62ad5 Mon Sep 17 00:00:00 2001 From: XXIV <13811862+thechampagne@users.noreply.github.com> Date: Sun, 22 Oct 2023 00:19:13 +0300 Subject: [PATCH] add D example (#317) * add D example * add D binding link * add build command to D example --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 1f5396cf..fa3222aa 100644 --- a/README.md +++ b/README.md @@ -562,6 +562,33 @@ when isMainModule: zip_close(zip) ``` +#### [D](https://dlang.org) +> Third party binding: [thechampagne/zip-d](https://github.com/thechampagne/zip-d) + +```shell +$ dmd -L-lzip main.d +``` + +```d +extern(C) void* zip_open(const(char)* zipname, int level, char mode); +extern(C) void zip_close(void* zip); +extern(C) int zip_entry_open(void* zip, const(char)* entryname); +extern(C) int zip_entry_close(void* zip); +extern(C) int zip_entry_write(void* zip, const(void)* buf, size_t bufsize); + +void main() +{ + void* zip = zip_open("/tmp/d.zip", 6, 'w'); + scope(exit) zip_close(zip); + + zip_entry_open(zip, "test"); + scope(exit) zip_entry_close(zip); + + string content = "test content"; + zip_entry_write(zip, content.ptr, content.length); +} +``` + ### Check out more cool projects which use this library * [Filament](https://github.com/google/filament): Filament is a real-time physically based rendering engine for Android, iOS, Linux, macOS, Windows, and WebGL. It is designed to be as small as possible and as efficient as possible on Android.