<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[deflateinit2 compress string&#x2F;char mit zlib in gzip]]></title><description><![CDATA[<p>Also ich habe in einer helper Datei eine bool Funktion, die ein char Zippen soll und wenn alles gut verläuft true ausgibt.</p>
<p>Die Funktion wird mittels aufgerufen:</p>
<pre><code class="language-cpp">int inlen = data.size();

				int outlen;
				char* out = new char[inlen];
if (gzip_str(data.data(), inlen, out, &amp;outlen)) {
                    cout &lt;&lt; out &lt;&lt; endl; 
}
</code></pre>
<p>Da man das Rad ja bekanntlich nicht neu erfinden soll/muss habe ich mich der Funktion von <a href="http://abma.de/blog/2011/469" rel="nofollow">Matthias</a> bedient und ich finde den Fehler selbst nicht, sodass ich euch um Rat frage! Vielleicht habe ich auch selbst ein Brett vorm Kopf! (P.S.: zlib.h ist natürlich includiert)</p>
<pre><code class="language-cpp">bool gzip_str(const char* in, const int inlen, char* out, int *outlen) {
	z_stream zlibStreamStruct;
	zlibStreamStruct.zalloc = Z_NULL; // Set zalloc, zfree, and opaque to Z_NULL so
	zlibStreamStruct.zfree = Z_NULL; // that when we call deflateInit2 they will be
	zlibStreamStruct.opaque = Z_NULL; // updated to use default allocation functions.
	zlibStreamStruct.total_out = 0; // Total number of output bytes produced so far
	zlibStreamStruct.next_in = (Bytef*) in; // Pointer to input bytes
	zlibStreamStruct.avail_in = inlen; // Number

	int res = deflateInit2(&amp;zlibStreamStruct, Z_BEST_COMPRESSION,
			Z_DEFLATED, (15 + 16), 8, Z_DEFAULT_STRATEGY);
	if (res != Z_OK)
        return false;
        do {
        zlibStreamStruct.next_out = (Bytef*) out + zlibStreamStruct.total_out;
		zlibStreamStruct.avail_out = *outlen - zlibStreamStruct.total_out;
		res = deflate(&amp;zlibStreamStruct, Z_FINISH);
	} while (res == Z_OK);

	deflateEnd(&amp;zlibStreamStruct);
	*outlen = zlibStreamStruct.total_out;

	return true;
}
</code></pre>
<p>Also wenn ich out ausgebe, bleibt dieser leer, aber die Funktion gibt ein true zurück. Also ich hoffe ihr könnt mir diesbezüglich helfen.<br />
Falls jemand Anregungen weiss, so wäre ich ihm sehr dankbar.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/290560/deflateinit2-compress-string-char-mit-zlib-in-gzip</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 10:16:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/290560.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 28 Jul 2011 21:43:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to deflateinit2 compress string&#x2F;char mit zlib in gzip on Thu, 28 Jul 2011 21:57:28 GMT]]></title><description><![CDATA[<p>Also ich habe in einer helper Datei eine bool Funktion, die ein char Zippen soll und wenn alles gut verläuft true ausgibt.</p>
<p>Die Funktion wird mittels aufgerufen:</p>
<pre><code class="language-cpp">int inlen = data.size();

				int outlen;
				char* out = new char[inlen];
if (gzip_str(data.data(), inlen, out, &amp;outlen)) {
                    cout &lt;&lt; out &lt;&lt; endl; 
}
</code></pre>
<p>Da man das Rad ja bekanntlich nicht neu erfinden soll/muss habe ich mich der Funktion von <a href="http://abma.de/blog/2011/469" rel="nofollow">Matthias</a> bedient und ich finde den Fehler selbst nicht, sodass ich euch um Rat frage! Vielleicht habe ich auch selbst ein Brett vorm Kopf! (P.S.: zlib.h ist natürlich includiert)</p>
<pre><code class="language-cpp">bool gzip_str(const char* in, const int inlen, char* out, int *outlen) {
	z_stream zlibStreamStruct;
	zlibStreamStruct.zalloc = Z_NULL; // Set zalloc, zfree, and opaque to Z_NULL so
	zlibStreamStruct.zfree = Z_NULL; // that when we call deflateInit2 they will be
	zlibStreamStruct.opaque = Z_NULL; // updated to use default allocation functions.
	zlibStreamStruct.total_out = 0; // Total number of output bytes produced so far
	zlibStreamStruct.next_in = (Bytef*) in; // Pointer to input bytes
	zlibStreamStruct.avail_in = inlen; // Number

	int res = deflateInit2(&amp;zlibStreamStruct, Z_BEST_COMPRESSION,
			Z_DEFLATED, (15 + 16), 8, Z_DEFAULT_STRATEGY);
	if (res != Z_OK)
        return false;
        do {
        zlibStreamStruct.next_out = (Bytef*) out + zlibStreamStruct.total_out;
		zlibStreamStruct.avail_out = *outlen - zlibStreamStruct.total_out;
		res = deflate(&amp;zlibStreamStruct, Z_FINISH);
	} while (res == Z_OK);

	deflateEnd(&amp;zlibStreamStruct);
	*outlen = zlibStreamStruct.total_out;

	return true;
}
</code></pre>
<p>Also wenn ich out ausgebe, bleibt dieser leer, aber die Funktion gibt ein true zurück. Also ich hoffe ihr könnt mir diesbezüglich helfen.<br />
Falls jemand Anregungen weiss, so wäre ich ihm sehr dankbar.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099225</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099225</guid><dc:creator><![CDATA[bla0r]]></dc:creator><pubDate>Thu, 28 Jul 2011 21:57:28 GMT</pubDate></item><item><title><![CDATA[Reply to deflateinit2 compress string&#x2F;char mit zlib in gzip on Fri, 29 Jul 2011 07:36:53 GMT]]></title><description><![CDATA[<p><code>out</code> ist ein Zeiger. Vielleicht willst du den Inhalt ausgeben...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099294</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Fri, 29 Jul 2011 07:36:53 GMT</pubDate></item></channel></rss>