I wrote this in python. It works but it's a slow as fuck.
Adjust the 3 constants at the top accordingly.
import sys
src = r''
output = r''
blockSize = 1024 * 1024
with open(src, 'rb') as inFile, open(output, 'wb') as outFile:
nZeroes = 0
eof = False
while not eof:
inByte = inFile.read(1)
if not inByte:
eof = True
elif inByte == b'\x00':
nZeroes = (nZeroes + 1) % blockSize
else:
for _ in range(nZeroes):
outFile.write(b'\x00')
nZeroes = 0
outFile.write(inByte)
for _ in range(nZeroes):
outFile.write(b'\x00')