Skip to content

Commit d6aa1ae

Browse files
authored
Merge pull request #3 from purescript-web/blob-constructor
Adds bindings for the Blob constructor
2 parents a5f4266 + 6752b84 commit d6aa1ae

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Web/File/Blob.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
exports.typeImpl = function (blob) { return blob.type; };
44

5+
exports.blobImpl = function (args) {
6+
return function (mediaType) {
7+
return new Blob(args, {type: mediaType});
8+
};
9+
};
10+
511
exports.size = function (blob) { return blob.size; };
612

713
exports.slice = function (contentType) {

src/Web/File/Blob.purs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module Web.File.Blob
22
( Blob
3+
, fromString
4+
, fromArray
35
, type_
46
, size
57
, StartByte(..)
@@ -20,6 +22,19 @@ import Unsafe.Coerce (unsafeCoerce)
2022

2123
foreign import data Blob :: Type
2224

25+
-- | Creates a String with the given Mediatype
26+
-- | For example:
27+
-- | ```
28+
-- | myBlob = fromString (unsafeStringify { name: "Carl", age: 25 }) (MediaType "application/json")
29+
-- | ```
30+
fromString :: String -> MediaType -> Blob
31+
fromString str ct = blobImpl [str] ct
32+
33+
-- | Creates a Blob from an Array of strings with the given Mediatype
34+
fromArray :: Array String -> MediaType -> Blob
35+
fromArray args opts = blobImpl args opts
36+
37+
foreign import blobImpl :: Array String -> MediaType -> Blob
2338
foreign import typeImpl :: Blob -> String
2439

2540
-- | `MediaType` of the data contained in the `Blob`.

0 commit comments

Comments
 (0)