Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
376 changes: 240 additions & 136 deletions bin/index.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"GlobalWebIndex/cmd-extra": "1.4.0",
"Janiczek/elm-vlq": "1.0.0",
"bburdette/toop": "1.2.0",
"danfishgold/base64-bytes": "1.1.0",
"dasch/levenshtein": "1.0.3",
"elm/bytes": "1.0.8",
"elm/core": "1.0.5",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm-community/array-extra": "2.6.0",
Expand All @@ -24,13 +28,12 @@
"obiloud/numeric-decimal": "3.0.1",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/elm-syntax": "7.3.8",
"the-sett/elm-pretty-printer": "3.1.0",
"truqu/elm-base64": "2.0.4"
"the-sett/elm-pretty-printer": "3.1.0"
},
"indirect": {
"andre-dietrich/parser-combinators": "4.1.0",
"elm/file": "1.0.5",
"elm/parser": "1.1.0",
"elm/regex": "1.0.0",
"fredcy/elm-parseint": "2.0.1",
"miniBill/elm-unicode": "1.1.1",
"pilatch/flip": "1.0.0",
Expand All @@ -43,7 +46,6 @@
"elm-explorations/test": "2.2.0"
},
"indirect": {
"elm/bytes": "1.0.8",
"elm/html": "1.0.0",
"elm/random": "1.0.0",
"elm/virtual-dom": "1.0.3"
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"adm-zip": "^0.5.16",
"form-data": "^4.0.1",
"mock-xmlhttprequest": "^8.4.1",
"tmp": "^0.2.3",
"which": "^5.0.0"
},
Expand Down
292 changes: 292 additions & 0 deletions src/Base64/Encode.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
module Base64.Encode exposing (encode)

import Bitwise exposing (and, or, shiftLeftBy, shiftRightZfBy)
import Char



-- Copied from <https://github.com/truqu/elm-base64/blob/2.0.4/src/Base64/Encode.elm> because
-- of clash with `danfishgold/base64-bytes` dependency.


encode : String -> String
encode input =
String.foldl chomp initial input |> wrapUp


initial : Accumulator
initial =
( "", 0, 0 )


wrapUp : Accumulator -> String
wrapUp ( res, cnt, acc ) =
case cnt of
1 ->
res
++ (shiftRightZfBy 2 acc |> and 0x3F |> intToBase64)
++ (shiftLeftBy 4 acc |> and 0x3F |> intToBase64)
++ "=="

2 ->
res
++ (shiftRightZfBy 10 acc |> and 0x3F |> intToBase64)
++ (shiftRightZfBy 4 acc |> and 0x3F |> intToBase64)
++ (shiftLeftBy 2 acc |> and 0x3F |> intToBase64)
++ "="

_ ->
res


type alias Accumulator =
( String, Int, Int )


chomp : Char -> Accumulator -> Accumulator
chomp char_ acc =
let
char : Int
char =
Char.toCode char_
in
if char < 0x80 then
acc
|> add char

else if char < 0x0800 then
acc
|> add (or 0xC0 (shiftRightZfBy 6 char))
|> add (or 0x80 (and 0x3F char))

else if char < 0xD800 || char >= 0xE000 && char <= 0xFFFF then
acc
|> add (or 0xE0 (shiftRightZfBy 12 char))
|> add (or 0x80 (and 0x3F (shiftRightZfBy 6 char)))
|> add (or 0x80 (and 0x3F char))

else
acc
|> add (or 0xF0 (shiftRightZfBy 18 char))
|> add (or 0x80 (and 0x3F (shiftRightZfBy 12 char)))
|> add (or 0x80 (and 0x3F (shiftRightZfBy 6 char)))
|> add (or 0x80 (and 0x3F char))


add : Int -> Accumulator -> Accumulator
add char ( res, count, acc ) =
let
current : Int
current =
or (shiftLeftBy 8 acc) char
in
case count of
2 ->
( res ++ toBase64 current, 0, 0 )

_ ->
( res, count + 1, current )


toBase64 : Int -> String
toBase64 int =
(shiftRightZfBy 18 int |> and 0x3F |> intToBase64)
++ (shiftRightZfBy 12 int |> and 0x3F |> intToBase64)
++ (shiftRightZfBy 6 int |> and 0x3F |> intToBase64)
++ (shiftRightZfBy 0 int |> and 0x3F |> intToBase64)


intToBase64 : Int -> String
intToBase64 i =
case i of
0 ->
"A"

1 ->
"B"

2 ->
"C"

3 ->
"D"

4 ->
"E"

5 ->
"F"

6 ->
"G"

7 ->
"H"

8 ->
"I"

9 ->
"J"

10 ->
"K"

11 ->
"L"

12 ->
"M"

13 ->
"N"

14 ->
"O"

15 ->
"P"

16 ->
"Q"

17 ->
"R"

18 ->
"S"

19 ->
"T"

20 ->
"U"

21 ->
"V"

22 ->
"W"

23 ->
"X"

24 ->
"Y"

25 ->
"Z"

26 ->
"a"

27 ->
"b"

28 ->
"c"

29 ->
"d"

30 ->
"e"

31 ->
"f"

32 ->
"g"

33 ->
"h"

34 ->
"i"

35 ->
"j"

36 ->
"k"

37 ->
"l"

38 ->
"m"

39 ->
"n"

40 ->
"o"

41 ->
"p"

42 ->
"q"

43 ->
"r"

44 ->
"s"

45 ->
"t"

46 ->
"u"

47 ->
"v"

48 ->
"w"

49 ->
"x"

50 ->
"y"

51 ->
"z"

52 ->
"0"

53 ->
"1"

54 ->
"2"

55 ->
"3"

56 ->
"4"

57 ->
"5"

58 ->
"6"

59 ->
"7"

60 ->
"8"

61 ->
"9"

62 ->
"+"

_ ->
"/"
Loading