From 422859f583703c4344d6f6fe0d78f445150263fb Mon Sep 17 00:00:00 2001 From: Mario Lang Date: Sat, 29 Mar 2014 16:28:16 +0100 Subject: Decompress a polyglot book file if it was compressed. --- chess-polyglot.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'chess-polyglot.el') 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) -- cgit v1.2.3