Nuked: Probably Microwaved
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

react-native-file-type

0.0.2 • Public • Published

React Native - File Type

ReactNative: Detect the file type of a Buffer/Uint8Array by reading it from device (Android/iOS/Widnows) file system

This library is a React Native wrapper around sindresorhus/file-type node module.

The file type is detected by checking the magic number of the buffer.

sindresorhus/file-type: fileType(buffer) API, accepts a buffer of binary file data in order to determine it's meta data. Please find below usage for the same:

const readChunk = require('read-chunk');
const fileType = require('file-type');
const buffer = readChunk.sync('unicorn.png', 0, 4100);

fileType(buffer);
//=> {ext: 'png', mime: 'image/png'}

We have created this library for the ease of use. Based on local storage path provided we internally use RNFS to read file and js-base64 to convert data into Uint8Array buffer which is expected by sindresorhus/file-type: fileType(buffer) API

fileType('local-storage-path')

Before we dive into on how to use this library. We would like to thank all the contributor of sindresorhus/file-type for providing such a awesome nice, cool library

Install

npm install react-native-file-type

Internally we are using RNFS to read file. We have to link this library with our project:

react-native link react-native-fs

Usage

import fileType from 'react-native-file-type'

fileType('local-storage-path').then((type) => {
    //Ext: type.ext
    //MimeType: type.mime
})

Contribution

Any type of contribution will be very much appreciated

License

Copyright @2017 Pranav Raj Singh Chauhan

The React Native File Type is provided under the MIT License.

Keywords

none

install

npm i react-native-file-type

Downloadsweekly downloads

170

version

0.0.2

license

none

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar