Skip to content

Instantly share code, notes, and snippets.

@izikeros
Last active April 13, 2022 04:13
Show Gist options
  • Select an option

  • Save izikeros/e788a73f128237e8feccfaf7f361bb86 to your computer and use it in GitHub Desktop.

Select an option

Save izikeros/e788a73f128237e8feccfaf7f361bb86 to your computer and use it in GitHub Desktop.
Create signature of file without reading it.
import stat
def _sig(st):
"""Create signatures of files without reading them.
Can be used to determine if files are the same or not.
Example:
>>> s1 = _sig(os.stat(file_name))
"""
# described: https://stackoverflow.com/a/9854699/3247880
# from: Mercurial source code: https://hg.python.org/cpython/file/2.7/Lib/filecmp.py
return (stat.S_IFMT(st.st_mode),
st.st_size,
st.st_mtime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment