Skip to content
Permalink
Browse files

PR/573: Nick Terrell: Add zstd support

  • Loading branch information...
zoulasc committed Sep 16, 2016
1 parent c952a77 commit 5b8826616cb699b69f7a1cc7b5c0cbac4b5bed9b
Showing with 100 additions and 2 deletions.
  1. +51 −1 magic/Magdir/compress
  2. +5 −1 src/compress.c
  3. +1 −0 tests/zstd-3-skippable-frames.result
  4. +1 −0 tests/zstd-dictionary-0.result
  5. +1 −0 tests/zstd-dictionary-1.result
  6. +1 −0 tests/zstd-dictionary-2.result
  7. +1 −0 tests/zstd-skippable-frame-0.result
  8. +1 −0 tests/zstd-skippable-frame-4.result
  9. +1 −0 tests/zstd-skippable-frame-8.result
  10. +1 −0 tests/zstd-skippable-frame-C.result
  11. +1 −0 tests/zstd-v0.2-FF.result
  12. +1 −0 tests/zstd-v0.2-FF.testfile
  13. +1 −0 tests/zstd-v0.3-FF.result
  14. +1 −0 tests/zstd-v0.3-FF.testfile
  15. +1 −0 tests/zstd-v0.4-FF.result
  16. +1 −0 tests/zstd-v0.4-FF.testfile
  17. +1 −0 tests/zstd-v0.5-FF.result
  18. +1 −0 tests/zstd-v0.5-FF.testfile
  19. +1 −0 tests/zstd-v0.6-FF.result
  20. +1 −0 tests/zstd-v0.6-FF.testfile
  21. +1 −0 tests/zstd-v0.7-00.result
  22. +1 −0 tests/zstd-v0.7-21.result
  23. +1 −0 tests/zstd-v0.7-21.testfile
  24. +1 −0 tests/zstd-v0.7-22.result
  25. +1 −0 tests/zstd-v0.7-22.testfile
  26. +1 −0 tests/zstd-v0.8-00.result
  27. +1 −0 tests/zstd-v0.8-01.result
  28. +1 −0 tests/zstd-v0.8-01.testfile
  29. +1 −0 tests/zstd-v0.8-02.result
  30. +1 −0 tests/zstd-v0.8-02.testfile
  31. +1 −0 tests/zstd-v0.8-03.result
  32. +1 −0 tests/zstd-v0.8-03.testfile
  33. +1 −0 tests/zstd-v0.8-16.result
  34. +1 −0 tests/zstd-v0.8-16.testfile
  35. +1 −0 tests/zstd-v0.8-20.result
  36. +1 −0 tests/zstd-v0.8-20.testfile
  37. +1 −0 tests/zstd-v0.8-21.result
  38. +1 −0 tests/zstd-v0.8-21.testfile
  39. +1 −0 tests/zstd-v0.8-22.result
  40. +1 −0 tests/zstd-v0.8-22.testfile
  41. +1 −0 tests/zstd-v0.8-23.result
  42. +1 −0 tests/zstd-v0.8-23.testfile
  43. +1 −0 tests/zstd-v0.8-F4.result
  44. +1 −0 tests/zstd-v0.8-F4.testfile
  45. +1 −0 tests/zstd-v0.8-FF.result
  46. +1 −0 tests/zstd-v0.8-FF.testfile
@@ -1,5 +1,5 @@
#------------------------------------------------------------------------------
# $File: compress,v 1.64 2015/07/27 15:41:09 christos Exp $
# $File: compress,v 1.65 2015/12/04 20:48:03 christos Exp $
# compress: file(1) magic for pure-compression formats (no archives)
#
# compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc.
@@ -220,6 +220,56 @@
0 lelong 0x184c2102 LZ4 compressed data (v0.1-v0.9)
!:mime application/x-lz4

# Zstandard/LZ4 skippable frames
# https://github.com/facebook/zstd/blob/dev/zstd_compression_format.md
0 lelong&0xFFFFFFF0 0x184D2A50
>(4.l+8) indirect

# Zstandard Dictionary ID subroutine
0 name zstd-dictionary-id
# Single Segment = True
>0 byte &0x20 \b, Dictionary ID:
>>0 byte&0x03 0 None
>>0 byte&0x03 1
>>>1 byte x %u
>>0 byte&0x03 2
>>>1 leshort x %u
>>0 byte&0x03 3
>>>1 lelong x %u
# Single Segment = False
>0 byte ^0x20 \b, Dictionary ID:
>>0 byte&0x03 0 None
>>0 byte&0x03 1
>>>2 byte x %u
>>0 byte&0x03 2
>>>2 leshort x %u
>>0 byte&0x03 3
>>>2 lelong x %u

# Zstandard compressed data
# https://github.com/facebook/zstd/blob/dev/zstd_compression_format.md
0 lelong 0xFD2FB522 Zstandard compressed data (v0.2)
!:mime application/x-zstd
0 lelong 0xFD2FB523 Zstandard compressed data (v0.3)
!:mime application/x-zstd
0 lelong 0xFD2FB524 Zstandard compressed data (v0.4)
!:mime application/x-zstd
0 lelong 0xFD2FB525 Zstandard compressed data (v0.5)
!:mime application/x-zstd
0 lelong 0xFD2FB526 Zstandard compressed data (v0.6)
!:mime application/x-zstd
0 lelong 0xFD2FB527 Zstandard compressed data (v0.7)
!:mime application/x-zstd
>4 use zstd-dictionary-id
0 lelong 0xFD2FB528 Zstandard compressed data (v0.8+)
!:mime application/x-zstd
>4 use zstd-dictionary-id

# https://github.com/facebook/zstd/blob/dev/zstd_compression_format.md
0 lelong 0xEC30A437 Zstandard dictionary
!:mime application/x-zstd-dictionary
>4 lelong x (ID %u)

# AFX compressed files (Wolfram Kleff)
2 string -afx- AFX compressed file data

@@ -35,7 +35,7 @@
#include "file.h"

#ifndef lint
FILE_RCSID("@(#)$File: compress.c,v 1.97 2016/05/13 23:02:28 christos Exp $")
FILE_RCSID("@(#)$File: compress.c,v 1.98 2016/06/28 16:38:26 christos Exp $")
#endif

#include "magic.h"
@@ -132,6 +132,9 @@ static const char *lrzip_args[] = {
static const char *lz4_args[] = {
"lz4", "-cd", NULL
};
static const char *zstd_args[] = {
"zstd", "-cd", NULL
};

private const struct {
const void *magic;
@@ -154,6 +157,7 @@ private const struct {
{ "\3757zXZ\0", 6, xz_args }, /* XZ Utils */
{ "LRZI", 4, lrzip_args }, /* LRZIP */
{ "\004\"M\030",4, lz4_args }, /* LZ4 */
{ "\x28\xB5\x2F\xFD", 4, zstd_args }, /* zstd */
#ifdef ZLIBSUPPORT
{ zlibcmp, 0, zlib_args }, /* zlib */
#endif
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 1
@@ -0,0 +1 @@
Zstandard dictionary (ID 0)
@@ -0,0 +1 @@
Zstandard dictionary (ID 1)
@@ -0,0 +1 @@
Zstandard dictionary (ID 285212672)
@@ -0,0 +1 @@
Zstandard compressed data (v0.2)
@@ -0,0 +1 @@
Zstandard compressed data (v0.3)
@@ -0,0 +1 @@
Zstandard compressed data (v0.4)
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 1
@@ -0,0 +1 @@
Zstandard compressed data (v0.2)
@@ -0,0 +1 @@
"�/��
@@ -0,0 +1 @@
Zstandard compressed data (v0.3)
@@ -0,0 +1 @@
#�/��
@@ -0,0 +1 @@
Zstandard compressed data (v0.4)
@@ -0,0 +1 @@
$�/��
@@ -0,0 +1 @@
Zstandard compressed data (v0.5)
@@ -0,0 +1 @@
%�/��
@@ -0,0 +1 @@
Zstandard compressed data (v0.6)
@@ -0,0 +1 @@
&�/��
@@ -0,0 +1 @@
Zstandard compressed data (v0.7), Dictionary ID: None
@@ -0,0 +1 @@
Zstandard compressed data (v0.7), Dictionary ID: 1
@@ -0,0 +1 @@
'�/�!
@@ -0,0 +1 @@
Zstandard compressed data (v0.7), Dictionary ID: 513
@@ -0,0 +1 @@
'�/�"
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: None
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 2
@@ -0,0 +1 @@
(�/�
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 770
@@ -0,0 +1 @@
(�/�
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 84148994
@@ -0,0 +1 @@
(�/�
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 770
@@ -0,0 +1 @@
(�/�
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: None
@@ -0,0 +1 @@
(�/� 
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 1
@@ -0,0 +1 @@
(�/�!
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 513
@@ -0,0 +1 @@
(�/�"
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 67305985
@@ -0,0 +1 @@
(�/�#
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: None
@@ -0,0 +1 @@
(�/��
@@ -0,0 +1 @@
Zstandard compressed data (v0.8+), Dictionary ID: 67305985
@@ -0,0 +1 @@
(�/��

0 comments on commit 5b88266

Please sign in to comment.
You can’t perform that action at this time.