Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active May 6, 2019 20:06
Show Gist options
  • Save gladchinda/9475d99f79951e35468cbbdc556f8fbc to your computer and use it in GitHub Desktop.
Save gladchinda/9475d99f79951e35468cbbdc556f8fbc to your computer and use it in GitHub Desktop.
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' });
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);
// 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