uppy/examples/react-native-expo/tusFileReader.js
Kevin van Zonneveld 764c2ccada
Update Linter (#2796)
* relocate .vscode

* Switch to transloadit linter

* Update .eslintrc.json

* autofix code

* unlink and install eslint-config-transloadit@1.1.1

* Change 0 to "off"

* Don't change 'use strict'

* Do not vertically align

* disable key-spacing

* add import/no-extraneous-dependencies per package

* add more react/a11y warnings

* Revert "autofix code"

This reverts commit 14c8a8cde8.

* add import/no-extraneous-dependencies per example and main package

* autofix code (2)

* Allow devDependencies in ./bin

* Change import/no-extraneous-dependencies to warn again

* upgrade linter

* Set import/no-extraneous-dependencies to warn
2021-03-15 16:25:17 +00:00

31 lines
721 B
JavaScript

import * as Expo from 'expo'
import base64 from 'base64-js'
export default function getTusFileReader (file, chunkSize, cb) {
Expo.FileSystem.getInfoAsync(file.uri, { size: true }).then((info) => {
cb(null, new TusFileReader(file, info.size))
}).catch(cb)
}
class TusFileReader {
constructor (file, size) {
this.file = file
this.size = size
}
slice (start, end, cb) {
end = Math.min(end, this.size)
const options = {
encoding: Expo.FileSystem.EncodingTypes.Base64,
length: end - start,
position: start,
}
Expo.FileSystem.readAsStringAsync(this.file.uri, options).then((data) => {
cb(null, base64.toByteArray(data))
}).catch(cb)
}
close () {
}
}