From 61622a5826bd189127e2e5df9d46ae24d9475009 Mon Sep 17 00:00:00 2001 From: XXIV <13811862+thechampagne@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:44:37 +0300 Subject: [PATCH] add nim example (#316) * add nim example * remove public operators * add build command to nim example --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 6c6febc1..475d5198 100644 --- a/README.md +++ b/README.md @@ -535,6 +535,32 @@ main :: proc() { } ``` +#### [Nim](https://nim-lang.org) +> Third party binding: [thechampagne/nimzip](https://github.com/thechampagne/nimzip) + +```shell +$ nim c --passL:-lzip main.nim +``` + +```nim +proc zip_open(zipname: cstring, level: cint, mode: char): pointer {.importc.} +proc zip_close(zip: pointer) {.importc.} +proc zip_entry_open(zip: pointer, entryname: cstring): cint {.importc.} +proc zip_entry_close(zip: pointer): cint {.importc.} +proc zip_entry_write(zip: pointer, buf: pointer, bufsize: csize_t): cint {.importc.} + +when isMainModule: + var zip = zip_open("/tmp/nim.zip", 6, 'w') + + discard zip_entry_open(zip, "test") + + let content: cstring = "test content" + discard zip_entry_write(zip, content, csize_t(len(content))) + + discard zip_entry_close(zip) + zip_close(zip) +``` + ### 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.