1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Update ansible-test is_binary_file test.

Add hard-coded list of common text and binary extensions.
This commit is contained in:
Matt Clay 2018-03-20 23:32:45 -07:00
parent aee01564a9
commit 6352e67ab2

View file

@ -441,6 +441,55 @@ def is_binary_file(path):
:type path: str :type path: str
:rtype: bool :rtype: bool
""" """
assume_text = set([
'.cfg',
'.conf',
'.crt',
'.css',
'.html',
'.ini',
'.j2',
'.js',
'.json',
'.md',
'.pem',
'.ps1',
'.psm1',
'.py',
'.rst',
'.sh',
'.txt',
'.xml',
'.yaml',
'.yml',
])
assume_binary = set([
'.bin',
'.eot',
'.gz',
'.ico',
'.iso',
'.jpg',
'.otf',
'.p12',
'.png',
'.pyc',
'.rpm',
'.ttf',
'.woff',
'.woff2',
'.zip',
])
ext = os.path.splitext(path)[1]
if ext in assume_text:
return False
if ext in assume_binary:
return True
with open(path, 'rb') as path_fd: with open(path, 'rb') as path_fd:
return b'\0' in path_fd.read(1024) return b'\0' in path_fd.read(1024)