npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

next-reader

v0.1.18

Published

Base classe for read big file write by javaScript

Downloads

43

Readme

Build Status npm version

中文

About

The FileReader class provides native file-reading capabilities for modern browsers.

Sometimes we will read out the needs from large files. such as read a part of the text file to display on the browser. At this point need to read the file as fragmented to avoid the browser stuck.

FileReader is an asynchronous interface, so in the concurrent read need a program to manage these concurrent, pass the contents of the slices to the next operation with order.

You can wait for a slice finished then reading the next piece. because JavaScript is a single-threaded language, so the two ways not essentially different.

Install

npm install next-reader --save-dev

Reader

All Reader extends of BaseReader

ReaderOptions

  • {String} encode - default utf8
  • {Number} read_size - default file.size
  • {Number} concurrency - default 1
  • {Number} chunk_size - file's encode. default utf8, only supportutf8,default 1 << 16

BrowserFileReader(file, [options])

Params

Simple

import { BrowserFileReader } from 'next-reader'
const target = document.querySelector('#file')
target.onchange = () => {
  const file = target.files[0]
  const reader = new BrowserFileReader(file)
  reader.subscribe(
    (data, sequence) => console.log('onNext::', data, sequence),
    (error, already, read_size) => console.log('onError::', error, already, read_size),
    () => console.log('onCompleted')
  )
  reader.read()    // same as reader.readAsArrayBuffer()
  // or
  reader.readAsArrayBuffer()
  // or
  reader.readAsText()
  // or
  reader.readAsDataURL()
}

LineReaderOptions

Mixin ReaderOptions

  • {Boolean} ignore_line_break - default true

ReadLineAsUint8(file, [options])

Params

Simple

import { ReadLineAsUint8 } from 'next-reader'
const Type = ReadLineAsUint8.Type
const target = document.querySelector('#file')
target.onchange = () => {
  const file = target.files[0]
  const reader = new ReadLineAsUint8(file)
  reader.subscribe(
    (record) => {
      const {type, no, size, data} = record   
      if (type === Type.lines) {
        console.log(data.forEach(d => console.log(d)))
      }else if (type ===Type.line) {
        console.log(data, no, size)
      }
    },
    (error, already, read_size) => console.log('onError::', error, already, read_size),
    () => console.log('onCompleted')
  )
  reader.read()
}

ReadLineAsString(file, [options])

Params

Simple is same as ReadLineAsUint8

ReadCsvAsUint8(file, [options])

Params

Simple

import { ReadCsvAsUint8 } from 'next-reader'
const target = document.querySelector('#file')
target.onchange = () => {
  const file = target.files[0]
  const reader = new ReadCsvAsUint8(file)
  reader.subscribe(
    (record) => {
      const { lines, size } = record
      lines.forEach(record => {
        console.log(record.fields, record.size, record.no)
      })
      console.log(size)
    },
    (error, already, read_size) => console.log('onError::', error, already, read_size),
    () => console.log('onCompleted')
  )
  reader.read()
}

ReadCsvWithLines(file, lines, [options])

Params

Simple

import { ReadCsvWithLines } from 'next-reader'
const target = document.querySelector('#file')
target.onchange = () => {
  const file = target.files[0]
  const reader = new ReadCsvWithLines(file, 100)
  reader.subscribe(
    (record) => {
     const { lines, size } = record
       let total = 0
       lines.forEach(record => {
         console.log('No. %s: %s .%s', record.no, record.fields.toString(), record.size)
       })
       console.log('total => %s, size => %s', total, size)
    },
    (error, already, read_size) => console.log('onError::', error, already, read_size),
    () => console.log('onCompleted')
  )
  reader.read()
}

BaseReader

BaseReader extends of BaseObservable and implements AbstractReader

AbstractReader

Implements AbstractObservable

  • read()
  • pause()
  • resume()
  • enqueue()
  • onReadData()
  • onReadError(error, already, read_size)
  • onReadComplete()
  • readable()
  • validate(data)
  • result(data)

BaseObservable

Implements of AbstractObservable

AbstractObservable

  • subscribe(BaseObserverOrOnNext, onError, onComplete)
  • subscribeOnNext(...args)
  • subscribeOnError(...args)
  • subscribeOnComplete(...args)

BaseObserver

Implements AbstractObserver

AbstractObserver

  • onNext(...args)
  • onError(...args)
  • onComplete(...args)
  • destroy()
  • isDestroy()

License

MIT