|
2 | 2 | <script src="../testing.js"></script> |
3 | 3 |
|
4 | 4 | <script id=Blob> |
5 | | - const parts = ["\r\nthe quick brown\rfo\rx\r", "\njumps over\r\nthe\nlazy\r", "\ndog"]; |
6 | | - |
7 | | - // "transparent" ending should not modify the final buffer. |
8 | | - let blob1 = new Blob(parts); |
9 | | - let expected = parts.join(""); |
10 | | - testing.expectEqual(expected.length, blob1.size); |
11 | | - testing.expectEqual(expected, blob1.str); |
12 | | - |
13 | | - // "native" ending should modify the final buffer. |
14 | | - let blob2 = new Blob(parts, { endings: "native" }); |
15 | | - expected = "\nthe quick brown\nfo\nx\n\njumps over\nthe\nlazy\n\ndog"; |
16 | | - testing.expectEqual(expected.length, blob2.size); |
17 | | - testing.expectEqual(expected, blob2.str); |
| 5 | + { |
| 6 | + const parts = ["\r\nthe quick brown\rfo\rx\r", "\njumps over\r\nthe\nlazy\r", "\ndog"]; |
| 7 | + // "transparent" ending should not modify the final buffer. |
| 8 | + const blob = new Blob(parts); |
| 9 | + |
| 10 | + const expected = parts.join(""); |
| 11 | + testing.expectEqual(expected.length, blob.size); |
| 12 | + testing.async(blob.text(), result => testing.expectEqual(expected, result)); |
| 13 | + } |
| 14 | + |
| 15 | + { |
| 16 | + const parts = ["\rhello\r", "\nwor\r\nld"]; |
| 17 | + // "native" ending should modify the final buffer. |
| 18 | + const blob = new Blob(parts, { endings: "native" }); |
| 19 | + |
| 20 | + const expected = "\nhello\n\nwor\nld"; |
| 21 | + testing.expectEqual(expected.length, blob.size); |
| 22 | + testing.async(blob.text(), result => testing.expectEqual(expected, result)); |
| 23 | + } |
| 24 | +</script> |
| 25 | + |
| 26 | +<script id=Blob.stream> |
| 27 | + { |
| 28 | + const parts = ["may", "thy", "knife", "chip", "and", "shatter"]; |
| 29 | + const blob = new Blob(parts); |
| 30 | + const reader = blob.stream().getReader(); |
| 31 | + |
| 32 | + testing.async(reader.read(), ({ done, value }) => { |
| 33 | + const expected = new Uint8Array([109, 97, 121, 116, 104, 121, 107, 110, |
| 34 | + 105, 102, 101, 99, 104, 105, 112, 97, |
| 35 | + 110, 100, 115, 104, 97, 116, 116, 101, |
| 36 | + 114]); |
| 37 | + testing.expectEqual(false, done); |
| 38 | + testing.expectEqual(true, value instanceof Uint8Array); |
| 39 | + testing.expectEqual(expected, value); |
| 40 | + }); |
| 41 | + } |
| 42 | +</script> |
| 43 | + |
| 44 | +<!-- Firefox and Safari only --> |
| 45 | +<script id=Blob.bytes> |
| 46 | + { |
| 47 | + const parts = ["light ", "panda ", "rocks ", "!"]; |
| 48 | + const blob = new Blob(parts); |
| 49 | + |
| 50 | + testing.async(blob.bytes(), result => { |
| 51 | + const expected = new Uint8Array([108, 105, 103, 104, 116, 32, 112, 97, |
| 52 | + 110, 100, 97, 32, 114, 111, 99, 107, 115, |
| 53 | + 32, 33]); |
| 54 | + testing.expectEqual(true, result instanceof Uint8Array); |
| 55 | + testing.expectEqual(expected, result); |
| 56 | + }); |
| 57 | + } |
18 | 58 | </script> |
0 commit comments