-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return to early conversion to ByteBuffer
This eliminates the need to read InputStream more than once, but still leaves us requiring them to fit in memory. Fixes #67.
- Loading branch information
1 parent
f22110d
commit ad13a0f
Showing
5 changed files
with
42 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
(ns cognitect.aws.util-test | ||
(:require [clojure.test :refer :all] | ||
[clojure.java.io :as io] | ||
[cognitect.aws.util :as util])) | ||
[cognitect.aws.util :as util]) | ||
(:import [java.nio ByteBuffer] | ||
[java.util Random] | ||
[java.util Arrays])) | ||
|
||
(deftest test-input-stream->byte-array | ||
(is (= "hi" (slurp (util/input-stream->byte-array (io/input-stream (.getBytes "hi")))))) | ||
(testing "resets input-stream so it can be read again" | ||
(let [stream (io/input-stream (.getBytes "hi"))] | ||
(is (= (seq (.getBytes "hi")) (seq (util/input-stream->byte-array stream)))) | ||
(is (= "hi" (slurp stream)))))) | ||
(testing "works with a 1mb array" | ||
(let [input (byte-array (int (Math/pow 2 20))) | ||
rng (Random.) | ||
_ (.nextBytes rng input) | ||
output (util/input-stream->byte-array (io/input-stream input))] | ||
(is (Arrays/equals ^bytes input ^bytes output))))) | ||
|
||
(deftest test-sha-256 | ||
(testing "returns sha for empty string if given nil" | ||
(is (= (seq (util/sha-256 nil)) | ||
(seq (util/sha-256 "")) | ||
(seq (util/sha-256 (.getBytes "")))))) | ||
(testing "accepts string, byte array, or input stream" | ||
(testing "accepts string, byte array, or ByteBuffer" | ||
(is (= (seq (util/sha-256 "hi")) | ||
(seq (util/sha-256 (.getBytes "hi"))) | ||
(seq (util/sha-256 (io/input-stream (.getBytes "hi")))))))) | ||
(seq (util/sha-256 (ByteBuffer/wrap (.getBytes "hi")))))))) |