#include <FileConstants.au3>
Global $sFile = 'big.txt', $bText, $bReplace, $hFile, $hFileNew, $iPos = 0x00010030, $iSize, _
$iMod, $iEnd, $iPart = 1024 * 1024 * 10, $iTime, $iTmp = 0, $iLen
;Без проверок на ошибки
;#cs
;долго пишет новый файл 100 Mb
$hFile = FileOpen(@ScriptDir & '\' & $sFile, 16 + 2)
For $j = 1 To 100
$bText = ''
For $i = 1 To 1024 * 1024
$bText &= Chr($iTmp)
$iTmp += 1
Switch $iTmp
Case 256
$iTmp = 0
EndSwitch
Next
FileWrite($hFile, Binary($bText))
Next
FileClose($hFile)
$bText = ''
;#ce
For $i = 192 To 255
$bReplace &= Chr($i)
Next
ConsoleWrite('Строка замены String: ' & $bReplace & @LF)
$bReplace = Binary($bReplace)
ConsoleWrite('Строка замены Binary: ' & $bReplace & @LF)
$iLen = BinaryLen($bReplace)
;читаем до изменения
$hFile = FileOpen(@ScriptDir & '\' & $sFile, 16)
FileSetPos($hFile, $iPos, $FILE_BEGIN)
$bText = FileRead($hFile, $iLen)
FileClose($hFile)
ConsoleWrite('до Binary: ' & $iPos & @TAB & $bText & @LF)
ConsoleWrite('до String: ' & $iPos & @TAB & BinaryToString($bText) & @LF)
$iTime = TimerInit()
$iSize = FileGetSize(@ScriptDir & '\' & $sFile)
$hFile = FileOpen(@ScriptDir & '\' & $sFile, 16)
$hFileNew = FileOpen(@ScriptDir & '\New_' & $sFile, 16 + 2)
If $iPos > $iPart Then
$iTmp = Int($iPos / $iPart)
$iMod = Mod($iPos, $iPart)
For $i = 1 To $iTmp
$bText = FileRead($hFile, $iPart)
FileWrite($hFileNew, $bText)
Next
$bText = FileRead($hFile, $iMod)
FileWrite($hFileNew, $bText & $bReplace)
FileRead($hFile, $iLen)
While 1
$bText = FileRead($hFile, $iPart)
If @error Then ExitLoop
FileWrite($hFileNew, $bText)
WEnd
Else
$bText = FileRead($hFile, $iPos)
$bText &= $bReplace
FileWrite($hFileNew, $bText)
FileRead($hFile, $iLen)
While 1
$bText = FileRead($hFile, $iPart)
If @error Then ExitLoop
FileWrite($hFileNew, $bText)
WEnd
EndIf
FileClose($hFile)
FileClose($hFileNew)
ConsoleWrite('Time: ' & TimerDiff($iTime) & @LF)
$bText = ''
FileMove(@ScriptDir & '\New_' & $sFile, @ScriptDir & '\' & $sFile, 1)
;читаем после изменения
$hFile = FileOpen(@ScriptDir & '\' & $sFile, 16)
FileSetPos($hFile, $iPos, $FILE_BEGIN)
$bText = FileRead($hFile, $iLen)
FileClose($hFile)
ConsoleWrite('после Binary: ' & $iPos & @TAB & $bText & @LF)
ConsoleWrite('после String: ' & $iPos & @TAB & BinaryToString($bText) & @LF)