{"id":16981544,"url":"https://github.com/charonn0/rb-zlib","last_synced_at":"2026-01-04T17:05:41.717Z","repository":{"id":63645653,"uuid":"20325526","full_name":"charonn0/RB-zlib","owner":"charonn0","description":"A Realbasic and Xojo binding to zlib","archived":false,"fork":false,"pushed_at":"2024-07-07T22:47:11.000Z","size":639,"stargazers_count":7,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-26T17:48:31.832Z","etag":null,"topics":["compression","deflate-format","gzip","gzip-format","realbasic","tar","xojo","zip","zlib"],"latest_commit_sha":null,"homepage":"http://www.boredomsoft.org/rb-zlib.bs","language":"REALbasic","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/charonn0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"charonn0"}},"created_at":"2014-05-30T10:12:00.000Z","updated_at":"2024-08-21T22:46:05.000Z","dependencies_parsed_at":"2024-07-07T23:51:40.790Z","dependency_job_id":null,"html_url":"https://github.com/charonn0/RB-zlib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charonn0%2FRB-zlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charonn0%2FRB-zlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charonn0%2FRB-zlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charonn0%2FRB-zlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charonn0","download_url":"https://codeload.github.com/charonn0/RB-zlib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244883480,"owners_count":20526041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compression","deflate-format","gzip","gzip-format","realbasic","tar","xojo","zip","zlib"],"created_at":"2024-10-14T02:05:46.462Z","updated_at":"2026-01-04T17:05:41.675Z","avatar_url":"https://github.com/charonn0.png","language":"REALbasic","funding_links":["https://github.com/sponsors/charonn0"],"categories":[],"sub_categories":[],"readme":"## Introduction\n[zlib](http://www.zlib.net/) is the reference implementation for the [deflate](https://en.wikipedia.org/wiki/DEFLATE) compression algorithm. Deflate is the algorithm used by the [gzip](https://tools.ietf.org/html/rfc1952) container format, the [zip](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) archive format, and [HTTP compression](https://tools.ietf.org/html/rfc7694).\n\n**RB-zlib** is a zlib [binding](http://en.wikipedia.org/wiki/Language_binding) for Realbasic and Xojo projects.\n\nThe minimum supported zlib version is 1.2.8. The minimum supported Xojo version is RS2009R3. \n\n## Highlights\n* Read and write compressed file or memory streams using a simple [BinaryStream work-alike](https://github.com/charonn0/RB-zlib/wiki/zlib.ZStream).\n* [Read](https://github.com/charonn0/RB-zlib/wiki/PKZip.ZipReader) and [write](https://github.com/charonn0/RB-zlib/wiki/PKZip.ZipWriter) zip archives (.zip)\n* [Read](https://github.com/charonn0/RB-zlib/wiki/USTAR.TarReader) and [write](https://github.com/charonn0/RB-zlib/wiki/USTAR.TarWriter) tape archives (.tar), with or without gzip compression.\n* Supports gzip, deflate, and raw deflate compressed streams\n* Supports Windows, Linux, and OS X.\n* 64-bit ready.\n\n## Become a sponsor\nIf you use this code in a commercial project, or just want to show your appreciation, please consider sponsoring me through GitHub. https://github.com/sponsors/charonn0\n\n## Getting started\nThe following section covers using zlib for general purpose compression. Refer to the [PKZip](https://github.com/charonn0/RB-zlib/wiki/PKZip) and [USTAR](https://github.com/charonn0/RB-zlib/wiki/USTAR) modules for information on working with archives.\n\n### Utility methods\nThe zlib module provides several utility methods for basic compression or decompression of data:\n\n* [**`Deflate`**](https://github.com/charonn0/RB-zlib/wiki/zlib.Deflate)\n* [**`Inflate`**](https://github.com/charonn0/RB-zlib/wiki/zlib.Inflate)\n* [**`GZip`**](https://github.com/charonn0/RB-zlib/wiki/zlib.GZip)\n* [**`GUnZip`**](https://github.com/charonn0/RB-zlib/wiki/zlib.GUnZip)\n\nAll of these methods are overloaded with several useful variations on input and output parameters. All variations follow either this signature:\n\n```realbasic\n function(source, destination, options[...]) As Boolean\n```\nor this signature:\n```realbasic\n function(source, options[...]) As MemoryBlock\n```\n\nwhere `source` is a `MemoryBlock`, `FolderItem`, or an object which implements the `Readable` interface; and `destination` (when provided) is a `FolderItem` or an object which implements the `Writeable` interface. Methods that do not have a `Destination` parameter return output as a `MemoryBlock` instead. Refer to the [examples](https://github.com/charonn0/RB-zlib/wiki#more-examples) below for demonstrations of some of these functions.\n\nAdditional optional arguments may be passed, to control the compression level, strategy, dictionary, and encoding. For example, `GZip` and `GUnZip` are just wrappers around `Deflate` and `Inflate` with options that specify the gzip format.\n\n### ZStream class\nThe second way to compress or decompress data is with the [`ZStream`](https://github.com/charonn0/RB-zlib/wiki/zlib.ZStream) class. The `ZStream` is a `BinaryStream` work-alike and implements both the `Readable` and `Writeable` interfaces. Anything [written](https://github.com/charonn0/RB-zlib/wiki/zlib.ZStream.Write) to a `ZStream` is compressed and emitted to the output stream (another `Writeable`); [reading](https://github.com/charonn0/RB-zlib/wiki/zlib.ZStream.Read) from a `ZStream` decompresses data from the input stream (another `Readable`).\n\nInstances of `ZStream` can be created from MemoryBlocks, FolderItems, and objects that implement the `Readable` and/or `Writeable` interfaces. For example, creating an in-memory compression stream from a zero-length MemoryBlock and writing a string to it:\n\n```realbasic\n  Dim output As New MemoryBlock(0)\n  Dim z As New zlib.ZStream(output) ' zero-length creates a compressor\n  z.Write(\"Hello, world!\")\n  z.Close\n```\nThe string will be processed through the compressor and written to the `output` MemoryBlock. To create a decompressor pass a MemoryBlock whose size is \u003e 0 (continuing from above):\n\n```realbasic\n  z = New zlib.ZStream(output) ' output contains the compressed string\n  MsgBox(z.ReadAll) ' read the decompressed string\n```\n\n### Inflater and Deflater classes\nThe third and final way to use zlib is through the [Inflater](https://github.com/charonn0/RB-zlib/wiki/zlib.Inflater) and [Deflater](https://github.com/charonn0/RB-zlib/wiki/zlib.Deflater) classes. These classes provide a low-level wrapper to the zlib API. All compression and decompression done using the `ZStream` class or the utility methods is ultimately carried out by an instance of `Deflater` and `Inflater`, respectively.\n\n```realbasic\n  Dim d As New zlib.Deflater()\n  Dim data As MemoryBlock = d.Deflate(\"H\")\n  data = data + d.Deflate(\"el\")\n  data = data + d.Deflate(\"lo\", zlib.Z_FINISH)\n  \n  Dim i As New zlib.Inflater()\n  data = i.Inflate(data)\n  MsgBox(data)\n```\n\n## More examples\nThis example compresses and decompresses a MemoryBlock using deflate compression:\n```realbasic\n  Dim data As MemoryBlock = \"Potentially very large MemoryBlock goes here!\"\n  Dim comp As MemoryBlock = zlib.Deflate(data)\n  Dim dcmp As MemoryBlock = zlib.Inflate(comp)\n```\n\nThis example compresses and decompresses a MemoryBlock using GZip:\n```realbasic\n  Dim data As MemoryBlock = \"Potentially very large MemoryBlock goes here!\"\n  Dim comp As MemoryBlock = zlib.GZip(data)\n  Dim dcmp As MemoryBlock = zlib.GUnZip(comp)\n```\n\nThis example gzips a file:\n\n```realbasic\n  Dim src As FolderItem = GetOpenFolderItem(\"\") ' a file to be gzipped\n  Dim dst As FolderItem = src.Parent.Child(src.Name + \".gz\")\n  If zlib.GZip(src, dst) Then \n    MsgBox(\"Compression succeeded!\")\n  Else\n    MsgBox(\"Compression failed!\")\n  End If\n```\n\nThis example opens an existing gzip file and decompresses it into a `MemoryBlock`:\n```realbasic\n  Dim f As FolderItem = GetOpenFolderItem(\"\") ' the gzip file to open\n  Dim data As MemoryBlock = zlib.GUnZip(f)\n  If data \u003c\u003e Nil Then\n    MsgBox(\"Decompression succeeded!\")\n  Else\n    MsgBox(\"Decompression failed!\")\n  End If\n```\n\nThis example extracts a zip archive into a directory:\n```realbasic\n  Dim src As FolderItem = GetOpenFolderItem(\"\") ' a zip file to extract\n  Dim dst As FolderItem = SelectFolder() ' the destination directory\n  Dim extracted() As FolderItem ' the list of extracted files/folders\n  extracted = PKZip.ReadZip(src, dst)\n```\n\nThis example performs an HTTP request that asks for compression, and decompresses the response:\n\n```realbasic\n  Dim h As New URLConnection\n  h.RequestHeader(\"Accept-Encoding\") = \"gzip, deflate\"\n  Dim page As String = h.SendSync(\"GET\", \"http://www.example.com\", 10)\n  If h.ResponseHeader(\"Content-Encoding\") = \"gzip\" Then\n    page = zlib.GUnZip(page)\n  ElseIf h.ResponseHeader(\"Content-Encoding\") = \"deflate\" Then\n    page = zlib.Inflate(page) ' assume DEFLATE_ENCODING; some servers send RAW_ENCODING\n  End If\n```\n\nThis example performs a hand-rolled HTTP request using a TCPSocket, and demonstrates how the ZStream can be used with any object that implements the `Readable` and/or `Writeable` interfaces:\n\n```realbasic\n  Static CRLF As String = EndOfLine.Windows\n  Dim sock As New TCPSocket\n  sock.Address = \"www.example.com\"\n  sock.Port = 80\n  sock.Connect()\n  Do Until sock.IsConnected\n    sock.Poll\n  Loop Until sock.LastErrorCode \u003c\u003e 0\n  sock.Write(\"GET / HTTP/1.0\" + CRLF + \"Accept-Encoding: gzip\" + CRLF + \"Connection: close\" + CRLF + \"Host: www.example.com\" + CRLF + CRLF)\n  Do\n    sock.Poll\n  Loop Until Not sock.IsConnected\n  \n  Dim headers As String = sock.Read(InStrB(sock.Lookahead, CRLF + CRLF) + 3)\n  Dim z As zlib.ZStream = zlib.ZStream.Open(sock)\n  Dim webpage As String = z.ReadAll ' read/decompress from the socket\n  z.Close\n```\n\n## How to incorporate these modules into your Realbasic/Xojo project\n### Import the `zlib`, `USTAR`, and/or `PKZip` modules\n1. Download the RB-zlib project either in [ZIP archive format](https://github.com/charonn0/RB-zlib/archive/master.zip) or by cloning the repository with your Git client.\n2. Open the RB-zlib project in REALstudio or Xojo. Open your project in a separate window.\n3. Copy the `zlib`, `USTAR`, and/or `PKZip` modules into your project and save.\n\nThe `zlib` module does not depend on either the `PKZip` or `USTAR` modules, and can be used separately.\n\nThe `PKZip` and `USTAR` modules do not depend on each other and can be used separately.\n\nThe `PKZip` and `USTAR` modules optionally depend on the `zlib` module for compression/decompression. To use them separately for reading and writing *un*compressed archives, set the `PKZip.USE_ZLIB` and/or `USTAR.USE_ZLIB` constants to `False`.\n\n### Ensure the zlib shared library is installed\nzlib is installed by default on most Unix-like operating systems, including OS X and most Linux distributions, however at least zlib version 1.2.8 is needed.\n\nWindows does not have it installed by default, you will need to ship the DLL with your application. You can use pre-built DLL available [here](http://zlib.net/zlib128-dll.zip) (Win32x86), or you can [build them yourself from source](http://zlib.net/zlib-1.2.8.tar.gz). \n\nRB-zlib will raise a PlatformNotSupportedException when used if all required DLLs/SOs/DyLibs are not available at runtime. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharonn0%2Frb-zlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharonn0%2Frb-zlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharonn0%2Frb-zlib/lists"}