Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@d33tah
Created June 12, 2015 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d33tah/09144ba0ce596a6b92ba to your computer and use it in GitHub Desktop.
Save d33tah/09144ba0ce596a6b92ba to your computer and use it in GitHub Desktop.
#!/usr/bin/env pypy
import json
import cStringIO
import sys
def main():
BUFSIZE = 10240
f = sys.stdin
decoder = json.JSONDecoder()
io = cStringIO.StringIO()
do_continue = True
while True:
read = f.read(BUFSIZE)
if len(read) < BUFSIZE:
do_continue = False
io.write(read)
try:
data, offset = decoder.raw_decode(io.getvalue())
print(data)
rest = io.getvalue()[offset:]
io.close()
io = cStringIO.StringIO()
if rest.startswith('\n'):
io.write(rest[1:])
else:
io.write(rest)
except ValueError, e:
#print(e)
#print(repr(io.getvalue()))
continue
if not do_continue:
break
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment