Last active
May 6, 2019 20:06
-
-
Save gladchinda/9475d99f79951e35468cbbdc556f8fbc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const data = { | |
name: 'Glad Chinda', | |
country: 'Nigeria', | |
role: 'Web Developer' | |
}; | |
// SOURCE 1: | |
// Creating a blob object from non-blob data using the Blob constructor | |
const blob = new Blob([ JSON.stringify(data) ], { type: 'application/json' }); |
This file contains hidden or 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
const paragraphs = [ | |
'First paragraph.\r\n', | |
'Second paragraph.\r\n', | |
'Third paragraph.' | |
]; | |
const blob = new Blob(paragraphs, { type: 'text/plain' }); | |
// SOURCE 2: | |
// Creating a new blob by slicing part of an already existing blob object | |
const slicedBlob = blob.slice(0, 100); |
This file contains hidden or 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
// SOURCE 3: | |
// Generating a blob object from a Web API like the Fetch API | |
// Notice that Response.blob() returns a promise that is fulfilled with a blob object | |
fetch('https://picsum.photos/id/6/100') | |
.then(response => response.blob()) | |
.then(blob => { | |
// use blob here... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment