Skip to content

Added support for lz4. #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Archive
- **ar** - ``application/x-unix-archive``
- **Z** - ``application/x-compress``
- **lz** - ``application/x-lzip``
- **lz4** - ``application/x-lz4``

Font
^^^^
Expand Down
1 change: 1 addition & 0 deletions filetype/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
archive.Ar(),
archive.Z(),
archive.Lz(),
archive.Lz4(),
)

# Supported archive container types
Expand Down
22 changes: 21 additions & 1 deletion filetype/types/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,27 @@ def match(self, buf):
buf[3] == 0x50)


class Lz4(Type):
"""
Implements the Lz4 archive type matcher.
"""
MIME = 'application/x-lz4'
EXTENSION = 'lz4'

def __init__(self):
super(Lz4, self).__init__(
mime=Lz4.MIME,
extension=Lz4.EXTENSION
)

def match(self, buf):
return (len(buf) > 3 and
buf[0] == 0x04 and
buf[1] == 0x22 and
buf[2] == 0x4D and
buf[3] == 0x18)


class Br(Type):
"""Implements the Br image type matcher."""

Expand Down Expand Up @@ -561,4 +582,3 @@ def __init__(self):

def match(self, buf):
return buf[:4] == bytearray([0xed, 0xab, 0xee, 0xdb])