MCPcopy
hub / github.com/iaddis/metalnes / flush

Method flush

data/roms/nes-test-roms/spritecans-2011/tools/8name.py:351–384  ·  view source on GitHub ↗

Compress the data to a file.

(self)

Source from the content-addressed store, hash-verified

349 self.write(''.join(seq))
350
351 def flush(self):
352 """Compress the data to a file."""
353 i = 0
354 base = 0
355 out = array('b')
356 while base < len(self.bytes):
357
358 # measure the run starting at t
359 i = 1
360 imax = min(128, len(self.bytes) - base)
361 basebyte = self.bytes[base]
362 while (i < imax
363 and basebyte == self.bytes[base + i]):
364 i += 1
365 # if the run is either length 3 or to the end of the file,
366 # write it
367 if i > 2 or base + i == len(self.bytes):
368 out.append(1 - i)
369 out.append(self.bytes[base])
370 base += i
371 continue
372
373 # measure the nonrun starting at t
374 i = 1
375 imax = min(128, len(self.bytes) - base)
376 while (i < imax
377 and (base + i + 2 >= len(self.bytes)
378 or self.bytes[base + i] != self.bytes[base + i + 1]
379 or self.bytes[base + i] != self.bytes[base + i + 2])):
380 i += 1
381 out.append(i - 1)
382 out.extend(self.bytes[base:base + i])
383 base += i
384 return out
385
386 @staticmethod
387 def test():

Callers 4

testMethod · 0.95
loadnamMethod · 0.45
savenamMethod · 0.45
testMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected