Socket
Book a DemoInstallSign in
Socket

expo-file-stream

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-file-stream

Stream file to Readable with no temp files

latest
Source
npmnpm
Version
1.1.3
Version published
Maintainers
1
Created
Source

expo-file-stream

expo-file-stream is a small library for creating read streams from files on mobile.

  • Supports multiple files in parallel.
  • Enables content:// URI on Android to be streamed without copy/open.
  • Compatible with Bare runtime
  • Powered by streamx

Install

npm i expo-file-stream

Usage

Below is a minimal example that mirrors the one in the repository’s example/App.tsx.

import { useCallback } from 'react'
import { Button, View } from 'react-native'
import { getDocumentAsync } from 'expo-document-picker'
import getMimeType from 'get-mime-type'
import { streamFile } from 'file-stream'

export default function App() {
  const onUpload = useCallback(async () => {
    const result = await getDocumentAsync({
      multiple: true,
      copyToCacheDirectory: false
    })

    if (result.canceled || !result.assets) return

    const assets = await Promise.all(
      result.assets.map(async ({ name, size, mimeType, uri }) => {
        return {
          name,
          byteLength: size ?? 0,
          type: mimeType || getMimeType(uri),
          uri,
          isOutsideAppCache: true
        }
      })
    )

    const target = assets[0].uri
    const stream = streamFile(target)

    stream.on('data', chunk => {
      console.log(chunk)
    })

    stream.on('end', () => {
      console.log('Upload complete')
    })
  }, [])

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Button title="Upload" onPress={onUpload} />
    </View>
  )
}

Hyperblobs

For use with Bare the library is designed to be easily streamed in to P2P friendly storage.

const Hyperblobs = require('hyperblobs')
const Corestore = require('corestore')

const store = new Corestore("./storage")
const core = store.get({ name:"my-blobs" })
const blobs = new Hyperblobs(core)
await blobs.ready()

const readStream = streamFile('content://com.android.providers.media.documents/document/image%3A62')
const writeStream = blobs.createWriteStream()
const pipeStream = readStream.pipe(writeStream)

pipeStream.on('finish',async () => {
  const blob = await blobs.get(writeStream.id)
  console.log(blob)
})

API

  • streamFile(uri: string): ReadableStream – Returns a streamx Readable that emits data chunks and an end event when the file has been fully read.
const stream = streamFile('content://com.android.providers.media.documents/document/image%3A62')
stream.on('data', chunk => console.log(chunk))
stream.on('end', () => console.log('done'))

Notes

  • When picking files from the document picker, set copyToCacheDirectory: false to obtain a raw content:// URI.
  • The returned stream can be piped to any writable destination

Keywords

react-native

FAQs

Package last updated on 16 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts