[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/plz 44e6f02064 17/81: Binary content
From: |
ELPA Syncer |
Subject: |
[elpa] externals/plz 44e6f02064 17/81: Binary content |
Date: |
Wed, 11 May 2022 17:57:58 -0400 (EDT) |
branch: externals/plz
commit 44e6f02064afb36559f968081a3ba1e612a72ea8
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Binary content
---
plz.el | 12 ++++++++----
tests/test-plz.el | 24 ++++++++++++++++++++++++
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/plz.el b/plz.el
index 51cf529446..5cb53f7cbb 100644
--- a/plz.el
+++ b/plz.el
@@ -190,7 +190,7 @@
(cl-defun plz-get (url &key headers as then else
(connect-timeout plz-connect-timeout)
- (decode t))
+ (decode t decode-s))
"Get HTTP URL with curl.
AS selects the kind of result to pass to the callback function
@@ -203,6 +203,7 @@ THEN. It may be:
narrowed to the response body (suitable for, e.g. `json-read').
If DECODE is non-nil, the response body is decoded automatically.
+For binary content, it should be nil.
THEN is a callback function, whose sole argument is selected
above with AS.
@@ -220,12 +221,13 @@ the initial connection attempt."
(plz--curl 'get url
:headers headers
:connect-timeout connect-timeout
- :decode decode
+ :decode (cond ((and decode-s (not decode)) nil)
+ (t decode))
:as as :then then :else else))
(cl-defun plz-get-sync (url &key headers as
(connect-timeout plz-connect-timeout)
- (decode t))
+ (decode t decode-s))
"Get HTTP URL with curl synchronously.
AS selects the kind of result to return. It may be:
@@ -236,6 +238,7 @@ AS selects the kind of result to return. It may be:
narrowed to the response body (suitable for, e.g. `json-read').
If DECODE is non-nil, the response body is decoded automatically.
+For binary content, it should be nil.
If the request fails, an error is signaled, either
`plz-curl-error' or `plz-http-error', as appropriate, with a
@@ -248,7 +251,8 @@ the initial connection attempt."
(plz--curl-sync 'get url
:headers headers
:connect-timeout connect-timeout
- :decode decode
+ :decode (cond ((and decode-s (not decode)) nil)
+ (t decode))
:as as))
;;;;; Private
diff --git a/tests/test-plz.el b/tests/test-plz.el
index a5d468a399..071730e8cf 100644
--- a/tests/test-plz.el
+++ b/tests/test-plz.el
@@ -40,6 +40,14 @@
;;;; Commands
+;;;; Macros
+
+(cl-defmacro plz-test-wait (process &optional (seconds 0.1) (times 100))
+ "Wait for SECONDS seconds TIMES times for PROCESS to finish."
+ `(cl-loop for i upto ,times ;; 10 seconds
+ while (equal 'run (process-status ,process))
+ do (sleep-for ,seconds)))
+
;;;; Functions
(defun plz-test-get-response (response)
@@ -147,6 +155,22 @@
(plz-response-p (plz-error-response (cdr err)))
(eq 404 (plz-response-status (plz-error-response (cdr
err))))))))
+;;;;; Binary
+
+(ert-deftest plz-test-get-jpeg ()
+ (let ((jpeg (plz-get-sync "https://httpbin.org/image/jpeg"
+ :decode nil)))
+ (should (image-jpeg-p jpeg)))
+
+ (let* ((test-jpeg)
+ (process (plz-get "https://httpbin.org/image/jpeg"
+ :decode nil
+ :as 'string
+ :then (lambda (string)
+ (setf test-jpeg string)))))
+ (plz-test-wait process)
+ (should (image-jpeg-p test-jpeg))))
+
;;;; Footer
(provide 'test-plz)
- [elpa] externals/plz c7c16e2123 04/81: Changes, (continued)
- [elpa] externals/plz c7c16e2123 04/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz debfc864c8 08/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz f0a0d114a6 01/81: Initial commit, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 2d20ca5030 02/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 5f54b5ebec 06/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 1016279174 07/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 897c5bbfb2 13/81: Improvements, error handling, ELPA Syncer, 2022/05/11
- [elpa] externals/plz e14ea7327d 14/81: Tidying, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 2b7944e0f9 05/81: Changes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 950a5498cb 16/81: Tidy, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 44e6f02064 17/81: Binary content,
ELPA Syncer <=
- [elpa] externals/plz 5bd683ead8 19/81: Tidy tests, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 3249835c8b 18/81: Tidy tests, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 21a7318f1c 26/81: Tests: Tidy/rename, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 3dd2598fe9 24/81: Tidy, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 3cc6747035 28/81: Meta: Add comm keyword, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 51404566fa 29/81: Notes: Add fetch.el, ELPA Syncer, 2022/05/11
- [elpa] externals/plz b77283748b 31/81: Meta: Update makem.sh, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 56c66c4421 32/81: Add/Change: :as 'binary, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 1bb701f1c1 36/81: Change/Fix: Downcase and intern header keys, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 6f8dfb83de 34/81: Tests: (plz-test-get-response) Change to macro, ELPA Syncer, 2022/05/11