<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Raw - Чтение / Запись]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=16117&amp;type=atom" />
	<updated>2021-02-21T23:31:17Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16117</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Raw - Чтение / Запись]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=146457#p146457" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>__Михаил__ пишет:</cite><blockquote><p>То что хранение в виде строк</p></blockquote></div><p>Нет, данные не хранятся в виде строк, любые данные в переменных, и бинарные, и текст, хранятся одинаково в виде бинарных данных. Но когда мы пытаемся получить содержимое таким образом<br /></p><div class="codebox"><pre><code>MsgBox, % buff</code></pre></div><p>AHK читает данные, находящиеся по адресу &amp;buff, как строку в UTF-16 (в Unicode версии), поэтому в случае бинарных данных либо другой кодировки на выходе получаем кракозябры.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-02-21T23:31:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=146457#p146457</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Raw - Чтение / Запись]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=146455#p146455" />
			<content type="html"><![CDATA[<p>Спасибо большое.<br />То что хранение в виде строк я знал, но то что всё настолько запущено нет.<br />Такие сложности, в справке даже не описано подробно.</p>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2021-02-21T23:09:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=146455#p146455</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Raw - Чтение / Запись]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=146454#p146454" />
			<content type="html"><![CDATA[<p>Когда сохраняете буфер так:<br /></p><div class="codebox"><pre><code>{&quot;Buf&quot;:Buf</code></pre></div><p>он сохраняется, как строка, а там не строка, а бинарные данные.<br />Можно так:<br /></p><div class="codebox"><pre><code>FileName = test.png
Data := OpenRaw(FileName)
MsgBox, % SaveRaw(Data.GetAddress(&quot;Buf&quot;), Data.Length, A_Desktop . &quot;\test.png&quot;)

OpenRaw(FileName)
{
   File := FileOpen(FileName, &quot;r&quot;)
   File.Pos := 0      ; Для текстовых файлов.
   len := File.Length
   Data := {}
   Data.SetCapacity(&quot;Buf&quot;, len)
   File.RawRead(Data.GetAddress(&quot;Buf&quot;), File.Length)
   Data.Length := len, Data.Encoding := File.Encoding
   File.Close()
   Return Data
}


SaveRaw(pData, Length, FileName)
{
    File := FileOpen(FileName, &quot;w&quot;)
    written := File.RawWrite(pData + 0, Length)
    File.Close()
    Return written
}</code></pre></div><p>Но проще так:<br /></p><div class="codebox"><pre><code>FileName = test.png
len := OpenRaw(FileName, buff, encoding)
MsgBox, % SaveRaw(&amp;buff, len, A_Desktop . &quot;\test.png&quot;)

OpenRaw(FileName, ByRef buff, ByRef encoding)
{
   File := FileOpen(FileName, &quot;r&quot;)
   File.Pos := 0      ; Для текстовых файлов.
   Return File.RawRead(buff, File.Length)
}


SaveRaw(pData, Length, FileName)
{
    Return FileOpen(FileName, &quot;w&quot;).RawWrite(pData + 0, Length)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-02-21T22:46:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=146454#p146454</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Raw - Чтение / Запись]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=146453#p146453" />
			<content type="html"><![CDATA[<p>Столкнулся с проблемой считывания содержимого из файлов.<br />С текстовыми файлами проблем нет, открыть / сохранить выходит.<br />Пытаюсь пересохранить .png файл - выходит пустой файл на выходе. При этом в Gui окошке есть текст, т.е. чтение происходит и проблема в самом методе сохранения в файл. Это видно в заголовке окна, 0 байт записано.<br />Ещё с текстом проблема, так как отображение нечитаемое, думаю нужно кодировать строки, но как правильно? Это всё же не основная проблема, главное сохранять .png файл.</p><div class="codebox"><pre><code>#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1


FileName = 0.png
;0.png
;N1.ini
;Текст.txt
;Test.ahk



File := OpenRaw(FileName)			; Открыть.
R := SaveRaw(File.Buf,File.Ret, &quot;SaveRaw-Test (&quot; File.Code &quot;).txt&quot;)	; Сохранить.

Gui Add, Edit, w360 h120, % File.Buf		; Показать содержимое.
Gui, Show,, % &quot;Записано: &quot; R &quot; байт, кодировка: &quot; File.Code
Return


OpenRaw(FileName)
{
 File := FileOpen(FileName, &quot;r&quot;)
 File.Pos := 0		; Для текстовых файлов.
 Ret := File.RawRead(Buf, File.Length)
 File.Close()
 Return {&quot;Buf&quot;:Buf, &quot;Ret&quot;:Ret, &quot;Code&quot;:File.Encoding}
}


SaveRaw(Buf, Length, FileName)
{
 File := FileOpen(FileName, &quot;w&quot;)
 R := File.RawWrite(Buf, Length)
 File.Close()
 Return R
}


Esc::
F4:: ExitApp
F6:: Reload
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2021-02-21T22:13:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=146453#p146453</id>
		</entry>
</feed>
