summaryrefslogtreecommitdiff
path: root/chess-polyglot.el
diff options
context:
space:
mode:
authorMario Lang <mlang@delysid.org>2014-03-29 16:28:16 +0100
committerMario Lang <mlang@delysid.org>2014-03-29 16:28:16 +0100
commit422859f583703c4344d6f6fe0d78f445150263fb (patch)
tree949072d12a9dee0b1d31822912a849a6838e9c94 /chess-polyglot.el
parent04cfa2a95b8eb8fb9f2d9e40532890ac6f7a2e8b (diff)
Decompress a polyglot book file if it was compressed.
Diffstat (limited to 'chess-polyglot.el')
-rw-r--r--chess-polyglot.el14
1 files changed, 14 insertions, 0 deletions
diff --git a/chess-polyglot.el b/chess-polyglot.el
index ceb0050..c124621 100644
--- a/chess-polyglot.el
+++ b/chess-polyglot.el
@@ -444,6 +444,20 @@ Returns a buffer object which contains the binary data."
(erase-buffer)
(set-buffer-multibyte nil)
(insert-file-contents-literally file)
+ (when (and (fboundp 'zlib-decompress-region)
+ (goto-char (point-min))
+ (re-search-forward "\\`\037\213\\(.\\)\\(.\\)\\(.\\)\\(.\\)\\(.\\)\\(.\\)\\(.\\)\\(.\\)" nil t)
+ (pcase (list (aref (match-string 1) 0)
+ (aref (match-string 2) 0)
+ (logior (aref (match-string 3) 0)
+ (lsh (aref (match-string 4) 0) 8)
+ (lsh (aref (match-string 5) 0) 16)
+ (lsh (aref (match-string 6) 0) 24))
+ (aref (match-string 7) 0)
+ (aref (match-string 8) 0))
+ (`(,method ,_ ,modified-epoch ,_ ,from-fs)
+ (and (= method 8) (> modified-epoch 0) (< from-fs 16)))))
+ (zlib-decompress-region (point-min) (point-max)))
(current-buffer))))
(defun chess-polyglot-book-plies (book position)