aboutsummaryrefslogtreecommitdiff
path: root/sx-encoding.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-11-11 09:00:02 -0500
committerSean Allred <code@seanallred.com>2014-11-11 09:00:02 -0500
commit6167df68eba9e8f69f285d47454afdce3ac94168 (patch)
tree4789ce43a6724563e7a9980afcd6b82ddcaca323 /sx-encoding.el
parent60a07cd274e80d9dfbb37f4d87a51e7b1d8af536 (diff)
parent92d30aeee31c80238a4ce5a825806dadc0e3a065 (diff)
Merge branch 'master' into network-list
Diffstat (limited to 'sx-encoding.el')
-rw-r--r--sx-encoding.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/sx-encoding.el b/sx-encoding.el
index 8ac12ca..0b72365 100644
--- a/sx-encoding.el
+++ b/sx-encoding.el
@@ -74,6 +74,35 @@
(substring ss 1))))))))
(replace-regexp-in-string "&[^; ]*;" get-function string)))
+(defun sx-encoding-gzipped-p (data)
+ "Checks for magic bytes in DATA.
+
+Check if the first two bytes of a string in DATA match magic
+numbers identifying the gzip file format. See [1] for the file
+format description.
+
+http://www.gzip.org/zlib/rfc-gzip.html
+
+http://emacs.stackexchange.com/a/2978"
+ (equal (substring (string-as-unibyte data) 0 2)
+ (unibyte-string 31 139)))
+
+(defun sx-encoding-gzipped-buffer-p (filename)
+ "Check if the BUFFER is gzip-compressed.
+
+See `gzip-check-magic' for details."
+ (sx-encoding-gzip-check-magic (buffer-string)))
+
+(defun sx-encoding-gzipped-file-p (file)
+ "Check if the FILE is gzip-compressed.
+
+See `gzip-check-magic' for details."
+ (let ((first-two-bytes (with-temp-buffer
+ (set-buffer-multibyte nil)
+ (insert-file-contents-literally file nil 0 2)
+ (buffer-string))))
+ (sx-encoding-gzipped-p first-two-bytes)))
+
(provide 'sx-encoding)
;;; sx-encoding.el ends here