1.1.4 • Published 5 years ago

@atayahmet/blobify v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Blobify

A Javascript automation tool to convert from html file object to blob object and more capabilities with creating custom helper function.

npm version Build Status Dependency Status Known Vulnerabilities GitHub license GitHub issues

Getting Started

import { chunk } from '@atayahmet/blobify';

chunk({ chars: stream, slice: 128, type: 'image/jpg' })

Installing

npm i @atayahmet/blobify --save

or

yarn add @atayahmet/blobify

Running the tests

npm test

Built-in Helpers

NameParameter TypeReturnDescription
pipeFunctionBlobify class instancePipe itarator.
createBlobstring[]BlobCreate blob object from chunks.
chunkIChunkOptionsUint8Array[]Chunk generator.
base64EncodeFilePromise<string>HTML5 File object.
base64DecodestringanyBase64 encoded data.
toStreamBlobPromise<string>Convert blob object to readable content.

IChunkOptions

NameTypeDescription
chunksstring or Uint8ArrayData format.
slicenumber (optional)Per chunk size. (Default 512)
typestringFile content type.

Quick Example

Convert the file to uploadable form.

import { pipe, chunk, createBlob, base64Encode } from '@atayahmet/blobify';

const file = document.getElementById('image');

pipe(() => base64Encode(file))
  .pipe(stream => chunk({ chars: stream, slice: 128 }))
  .pipe(chunks => createBlob(chunks, "image/jpeg"))
  .catch(console.error)
  .run()
  .then(resul => {
    console.log(result);
  });

Vice versa:

pipe(() => toStream(blob))
  .pipe(stream => base64Decode(stream))
  .pipe(data => {
      // do some maniplation...
      return data;
  })
  .run()
  .then(result => {
    // ...
  });

Built With

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details