Skip to content

Commit e32b2cf

Browse files
authored
Merge pull request h2non#82 from dosas/feature/issue-76
Added support for lz4.
2 parents 29e4eb8 + a34d95d commit e32b2cf

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Archive
132132
- **ar** - ``application/x-unix-archive``
133133
- **Z** - ``application/x-compress``
134134
- **lz** - ``application/x-lzip``
135+
- **lz4** - ``application/x-lz4``
135136

136137
Font
137138
^^^^

filetype/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
archive.Ar(),
8686
archive.Z(),
8787
archive.Lz(),
88+
archive.Lz4(),
8889
)
8990

9091
# Supported archive container types

filetype/types/archive.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,27 @@ def match(self, buf):
515515
buf[3] == 0x50)
516516

517517

518+
class Lz4(Type):
519+
"""
520+
Implements the Lz4 archive type matcher.
521+
"""
522+
MIME = 'application/x-lz4'
523+
EXTENSION = 'lz4'
524+
525+
def __init__(self):
526+
super(Lz4, self).__init__(
527+
mime=Lz4.MIME,
528+
extension=Lz4.EXTENSION
529+
)
530+
531+
def match(self, buf):
532+
return (len(buf) > 3 and
533+
buf[0] == 0x04 and
534+
buf[1] == 0x22 and
535+
buf[2] == 0x4D and
536+
buf[3] == 0x18)
537+
538+
518539
class Br(Type):
519540
"""Implements the Br image type matcher."""
520541

@@ -561,4 +582,3 @@ def __init__(self):
561582

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

0 commit comments

Comments
 (0)