Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. def has_string(stream, byteary):
  2.     """Quick function to check if a stream contains a byteary"""
  3.     if isinstance(byteary, str):
  4.         byteary = byteary.encode('utf-8')
  5.     import io
  6.     buf_len = len(byteary)
  7.     suffixes = [
  8.         byteary[-i:]
  9.         for i in range(3, buf_len)
  10.         ]
  11.  
  12.     whole = io.BytesIO()
  13.     while True:
  14.         r = stream.read(buf_len*32)
  15.         if not r:
  16.             break
  17.         whole.write(r)
  18.         if any(suf in r for suf in suffixes):
  19.             if byteary in whole.getvalue():
  20.                 return True
  21.     return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement