<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: WinHttpRequest, gzip, deflate]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14565&amp;type=atom" />
	<updated>2019-02-12T19:26:19Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=14565</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132163#p132163" />
			<content type="html"><![CDATA[<p>Ноль времени - это идеально.<br />Работает без нареканий.<br />Большое спасибо!</p>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2019-02-12T19:26:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132163#p132163</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132158#p132158" />
			<content type="html"><![CDATA[<p>Вот так вышло:<br /></p><div class="codebox"><pre><code>SetBatchLines, -1
zlibPath := &quot;D:\Downloads\zlib\bin\zlib1.dll&quot;

oHTTP := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
oHTTP.Open(&quot;GET&quot;, &quot;http://ahkscript.org/boards/&quot;, false)
oHTTP.SetRequestHeader(&quot;Accept-Encoding&quot;, &quot;gzip, deflate&quot;)
oHTTP.Send()
arr := oHTTP.ResponseBody
length := arr.MaxIndex() + 1
pData := NumGet( ComObjValue(arr) + 8 + A_PtrSize )

start := A_TickCount
size := gzip_inflate(zlibPath, pData, length, uncompr)
res := StrGet(&amp;uncompr, size, &quot;utf-8&quot;)

MsgBox, % &quot;Завершено за &quot; . A_TickCount - start . &quot; мс`n`n&quot; . res

gzip_inflate(zlib, pComprData, comprLen, ByRef uncompr) {
   static MAX_WBITS := 15, Z_OK := 0, Z_FINISH := 4, Z_STREAM_END := 1
        , errors := [&quot;Z_ERRNO&quot;, &quot;Z_STREAM_ERROR&quot;, &quot;Z_DATA_ERROR&quot;, &quot;Z_MEM_ERROR&quot;, &quot;Z_BUF_ERROR&quot;, &quot;Z_VERSION_ERROR&quot;]
        
   if !hLib := DllCall(&quot;LoadLibrary&quot;, Str, zlib, Ptr)
      throw Exception(&quot;Can&#039;t load zlib1.dll. A_LastError: &quot; . A_LastError)
   
   VarSetCapacity(uncompr, outMaxLen := comprLen*10, 0)
   VarSetCapacity(stream, szStream := 24 + 8*A_PtrSize, 0)
   NumPut(pComprData, stream)
   NumPut(comprLen, stream, A_PtrSize, &quot;UInt&quot;)
   NumPut(&amp;uncompr, stream, A_PtrSize + 8)
   NumPut(outMaxLen, stream, A_PtrSize + 8 + A_PtrSize, &quot;UInt&quot;)
   Loop 1 {
      res := DllCall(zlib . &quot;\inflateInit2_&quot;, Ptr, &amp;stream, Int, 16 + MAX_WBITS, AStr, &quot;1&quot;, Int, szStream)
      if ( res != Z_OK &amp;&amp; error := &quot;inflateInit2_: &quot; . errors[-res] )
         break
      
      res := DllCall(zlib . &quot;\inflate&quot;, Ptr, &amp;stream, Int, Z_FINISH)
      if ( res != Z_STREAM_END &amp;&amp; error := &quot;inflate: &quot; . errors[-res] )
         break
      
      res := DllCall(zlib . &quot;\inflateEnd&quot;, Ptr, &amp;stream)
      ( res != Z_OK &amp;&amp; error := &quot;inflateEnd: &quot; . errors[-res] )
   }
   DllCall(&quot;FreeLibrary&quot;, Ptr, hLib)
   if error
      throw Exception(error)
   Return outLen := NumGet(stream, A_PtrSize + 8 + A_PtrSize + 4, &quot;UInt&quot;)
}</code></pre></div><p>Не знаю, всё ли правильно.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-02-12T17:05:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132158#p132158</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132153#p132153" />
			<content type="html"><![CDATA[<p>Так надо:<br /></p><div class="codebox"><pre><code>VarSetCapacity(stream, 24 + 8*A_PtrSize, 0)
MsgBox, % DllCall(&quot;zlib1.dll\inflateInit2_&quot;, Ptr, &amp;stream, Int, 16 + (MAX_WBITS := 15), &quot;astr&quot;, 1, int, 24 + 8*A_PtrSize, &quot;cdecl&quot;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-02-12T14:54:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132153#p132153</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132144#p132144" />
			<content type="html"><![CDATA[<p>Пробовал с dll — что-то не вышло пока, на первой же функции возвращает Z_VERSION_ERROR (-6).<br /></p><div class="codebox"><pre><code>SetBatchLines, -1
zlibPath := &quot;C:\Program Files\Git\mingw64\libexec\git-core\zlib1.dll&quot;

oHTTP := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
oHTTP.Open(&quot;GET&quot;, &quot;http://ahkscript.org/boards/&quot;, false)
oHTTP.SetRequestHeader(&quot;Accept-Encoding&quot;, &quot;gzip, deflate&quot;)
oHTTP.Send()
arr := oHTTP.ResponseBody
length := arr.MaxIndex() + 1
pData := NumGet( ComObjValue(arr) + 8 + A_PtrSize )


gzip_inflate(zlibPath, pData, length, uncompr, length*10)
MsgBox, % uncompr

gzip_inflate(zlibPath, pData, inLength, uncompr, outLength) {
   if !DllCall(&quot;LoadLibrary&quot;, Str, zlibPath)
      throw Exception(&quot;Can&#039;t load zlib1.dll. A_LastError: &quot; . A_LastError)
   VarSetCapacity(uncompr, outLength, 0)
   VarSetCapacity(z_stream_s, A_PtrSize*4 + 4*10, 0)
   NumPut(pData, z_stream_s)
   NumPut(inLength, z_stream_s, A_PtrSize, &quot;UInt&quot;)
   NumPut(&amp;uncompr, z_stream_s, A_PtrSize + 8)
   NumPut(outLength, z_stream_s, A_PtrSize + 8 + A_PtrSize, &quot;UInt&quot;)
   MsgBox, % DllCall(zlibPath . &quot;\inflateInit2_&quot;, Ptr, &amp;z_stream_s, Int, 16 + (MAX_WBITS := 15))
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-02-12T10:18:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132144#p132144</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132141#p132141" />
			<content type="html"><![CDATA[<p>Нижайше кланяюсь!</p>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2019-02-12T09:23:05Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132141#p132141</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132139#p132139" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>Кстати, у меня какая-то комовская ошибка выскакивает.</p></blockquote></div><p>Подправил.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-02-12T07:05:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132139#p132139</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132138#p132138" />
			<content type="html"><![CDATA[<p>Вот <a href="https://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/Binaries%20%2864-bit%29/zlib-1.2.5-bin-x64.zip/download">здесь</a> 64-битная.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-02-12T04:56:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132138#p132138</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132137#p132137" />
			<content type="html"><![CDATA[<p>Действительно 32 бита.<br />Тогда надо на просторах инета искать.<br />Вариант через js годится, если скорость не так сильно важна, так как будет медленнее чем через dll.<br />Кстати, у меня какая-то комовская ошибка выскакивает.<br />StrData - 0x80020006 - Unknown name.<br />Можно еще попробовать перенести вариант с автоит - там разработчик вообще машинным кодом библиотеку прописал:<br /><a href="https://www.autoitscript.com/forum/topic/128962-zlib-deflateinflategzip-udf/?tab=comments#comment-1312432">https://www.autoitscript.com/forum/topi … nt-1312432</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-02-12T04:42:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132137#p132137</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132136#p132136" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>Современная dll для 64 бит систем: <a href="https://sourceforge.net/projects/libpng/files/zlib/1.2.3/zlib123-dll.zip/download?use_mirror=netix&amp;download=">https://sourceforge.net/projects/libpng … ;download=</a></p></blockquote></div><p>У меня по этой ссылке 32-битная скачивается.<br />Вот так с помощью js-библиотеки paco.js получилось:<br /></p><div class="codebox"><pre><code>SetBatchLines, -1

oHTTP := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
oHTTP.Open(&quot;GET&quot;, &quot;http://ahkscript.org/boards/&quot;, false)
oHTTP.SetRequestHeader(&quot;Accept-Encoding&quot;, &quot;gzip, deflate&quot;)
oHTTP.Send()
arr := oHTTP.ResponseBody
length := arr.MaxIndex() + 1
pData := NumGet( ComObjValue(arr) + 8 + A_PtrSize )

start := A_TickCount
res := GzipDecode(pData, length)

MsgBox, % &quot;Завершено за &quot; . A_TickCount - start . &quot; мс`n`n&quot; . res

GzipDecode(pData, size) {
   arr := &quot;[&quot;
   Loop % size
      arr .= (arr = &quot;[&quot; ? &quot;&quot; : &quot;,&quot;) . NumGet(pData + A_Index - 1, &quot;UChar&quot;)
   arr .= &quot;]&quot;

   html =
   (
   &lt;!DOCTYPE html&gt;
   &lt;html&gt;
   &lt;head&gt;
     &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
     &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.8/pako.min.js&quot;&gt;&lt;/script&gt;
     &lt;script&gt;
       var charData = %arr%;
       var binData  = new Uint8Array(charData);
       var data     = pako.inflate(binData);
       var strData  = String.fromCharCode.apply(null, new Uint16Array(data));
     &lt;/script&gt;
   &lt;/head&gt;
   &lt;/html&gt;
   )
   oDoc := ComObjCreate(&quot;htmlfile&quot;)
   oDoc.write(html)
   Loop {
      Sleep, 10
      try res := oDoc.parentWindow.strData
      catch
        continue
      break
   }
   Return res
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-02-12T03:42:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132136#p132136</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132135#p132135" />
			<content type="html"><![CDATA[<p>По-дефалту ZLib разархивирует формат zlib.<br />Чтобы он разархивировал gzip, как я понял, нужно будет указать в InflateInit2 - 31, после чего в цикле распаковывать через inflate().<br /><a href="https://www.zlib.net/zlib_how.html">https://www.zlib.net/zlib_how.html</a><br />Кстати, у меня код от <strong>lexikos</strong> на 32 бит ахк работает.<br />Ну и с массивом байт, думаю, не будет работать - нужен пойнтер + длина равна не result.MaxIndex(), а result.MaxIndex()+1.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-02-12T03:03:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132135#p132135</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132133#p132133" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>
Get() {
	oHTTP := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
    oHTTP.Open(&quot;GET&quot;, &quot;http://ahkscript.org/boards/&quot;, True)
    oHTTP.SetRequestHeader(&quot;Accept-Encoding&quot;, &quot;gzip, deflate&quot;)
    oHTTP.Send()
    oHTTP.WaitForResponse()
    Return oHTTP.ResponseBody
}
</code></pre></div><p>Возвращает массив байт.<br /></p><div class="codebox"><pre><code>
result := Get()
r := zlib_Decompress(decompress, result, result.MaxIndex())
MsgBox % StrGet(&amp;decompress, &quot;UTF-8&quot;) &quot;`n&quot; result.MaxIndex() &quot;`n&quot; r
</code></pre></div><p>В результате пустая строка. Подскажите пожалуйста, в чём ошибка?</p>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2019-02-11T22:40:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132133#p132133</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132132#p132132" />
			<content type="html"><![CDATA[<p><a href="http://forum.script-coding.com/viewtopic.php?id=12618">http://forum.script-coding.com/viewtopic.php?id=12618</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2019-02-11T21:20:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132132#p132132</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: WinHttpRequest, gzip, deflate]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=132131#p132131" />
			<content type="html"><![CDATA[<p>Всем добра!</p><p>При POST запросе, приходит ответом длиннющий JSON, содержимое которого не извлечь из-за того, что он сжат(gzip).<br />Пытался приспособить для нужд вариант <a href="https://www.autohotkey.com/boards/viewtopic.php?p=43678&amp;sid=53767fee34524d3c54c8aa162ac16fba#p43678">отсюда</a>, но как выяснилось, он сам по себе не рабочий.</p><p>Поиск не привёл к решению. Помогите пожалуйста побороть невзгоду.<br />Win 7 x64, AHK 1.1.30.01 x64</p>]]></content>
			<author>
				<name><![CDATA[KusochekDobra]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33846</uri>
			</author>
			<updated>2019-02-11T21:12:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=132131#p132131</id>
		</entry>
</feed>
