This repository was archived by the owner on Feb 23, 2019. It is now read-only.
File tree 2 files changed +60
-0
lines changed
2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -35,4 +35,40 @@ module Url {
35
35
})()
36
36
`
37
37
}
38
+
39
+ /*
40
+ Creates an url from the given content and type, which is available until the
41
+ current window is closed.
42
+
43
+ Url.createObjectUrlFromString("Content", "text/html")
44
+ */
45
+ fun createObjectUrlFromString (string : String , type : String ) : String {
46
+ `
47
+ (() => {
48
+ let blob = new Blob ([string], {type : type})
49
+ return URL .createObjectURL (blob)
50
+ })()
51
+ `
52
+ }
53
+
54
+ /*
55
+ Creates an url from the given file, which is available until the current
56
+ window is closed.
57
+
58
+ File.fromString("Content", "test.html", "text/html")
59
+ |> Url.createObjectUrlFromFile()
60
+ */
61
+ fun createObjectUrlFromFile (file : File ) : String {
62
+ `URL .createObjectURL (file)`
63
+ }
64
+
65
+ /*
66
+ Releases an existing object URL which was previously created.
67
+
68
+ Url.createObjectUrlFromString("Content", "text/html")
69
+ |> Url.revokeObjectUrl()
70
+ */
71
+ fun revokeObjectUrl (url : String ) : Void {
72
+ `URL .revokeObjectURL (url)`
73
+ }
38
74
}
Original file line number Diff line number Diff line change @@ -17,3 +17,27 @@ suite "Url.parse" {
17
17
}
18
18
}
19
19
}
20
+
21
+ suite "Url.createObjectUrlFromFile" {
22
+ test "it creates an url from a file" {
23
+ (File .fromString ("Content" , "test.html" , "text/html" )
24
+ |> Url .createObjectUrlFromFile ()) != ""
25
+ }
26
+ }
27
+
28
+ suite "Url.createObjectUrlFromString" {
29
+ test "it creates an url from a file" {
30
+ Url .createObjectUrlFromString ("Content" , "text/html" ) != ""
31
+ }
32
+ }
33
+
34
+ suite "Url.revokeObjectUrl" {
35
+ test "it revokes the given url" {
36
+ try {
37
+ Url .createObjectUrlFromString ("Content" , "text/html" )
38
+ |> Url .revokeObjectUrl ()
39
+
40
+ true
41
+ }
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments