Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: gunzip.cpp
- Revision:
- 3:ed54c8225fe6
- Parent:
- 1:2a3edb8df037
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gunzip.cpp Tue Feb 28 16:50:16 2017 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "zlib.h"
+
+/** GUNZIP a from src buffer to dst buffer
+ @param dst : destination buffer
+ @param dst_length : pointer to destination buffer length
+ @param src : source buffer
+ @param src_length : source buffer length
+ @return Z_OK on success, zlib error (<0) on failure
+ */
+extern "C" int gunzip(unsigned char *dst, unsigned long *dst_length, unsigned char *src, unsigned long src_length)
+{
+ z_stream stream;
+ memset(&stream, 0, sizeof(stream));
+
+ stream.next_in = src;
+ stream.avail_in = src_length;
+
+ stream.next_out = dst;
+ stream.avail_out = *dst_length;
+
+ int rv = inflateInit2(&stream, 15 + 16);
+ if (Z_OK == rv) {
+ rv = inflate(&stream, Z_NO_FLUSH);
+ if (Z_STREAM_END == rv) {
+ inflateEnd(&stream);
+ rv = Z_OK;
+ }
+ }
+
+ if (Z_OK == rv) {
+ *dst_length = stream.total_out;
+ } else {
+ *dst_length = 0;
+ }
+
+ return rv;
+}
\ No newline at end of file