How to use speedometer - 6 common examples

To help you get started, we’ve selected a few speedometer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beakerbrowser / beaker / app / background-process / ui / downloads.js View on Github external
// build a path to an unused name in the downloads folder
    let filePath = opts.saveAs ? opts.saveAs : unusedFilename.sync(path.join(app.getPath('downloads'), item.getFilename()))

    // track as an active download
    item.id = ('' + Date.now()) + ('' + Math.random()) // pretty sure this is collision proof but replace if not -prf
    item.name = path.basename(filePath)
    if (item.name.split('.').length < 2 && item.getMimeType()) {
      const ext = `.${mime.extension(item.getMimeType())}`
      if (ext !== '.bin') {
        item.name += ext
        filePath += ext
      }
    }
    item.setSavePath(filePath)
    item.isHandled = true
    item.downloadSpeed = speedometer()

    if (!opts.trusted) {
      item.pause()
      var allowed = await requestPermission('download', wc, {url: item.getURL(), filename: item.name})
      if (!allowed) {
        item.cancel()
        return
      }
      item.resume()
    }

    downloads.push(item)
    downloadsEvents.emit('new-download', toJSON(item))

    // update dock-icon progress bar
    var lastBytes = 0
github arso-project / archipel / packages / app / src / features / drive / UploadFile.js View on Github external
const [promise, done] = prom()

    const updateState = newState => this.setState(state => (
      { files: updateAt(state.files, i, newState) }
    ))

    updateState({ pending: true })

    let { path, api, archive } = this.props
    const key = archive

    let { name, webkitRelativePath } = file
    if (this.state.uploadDir) name = webkitRelativePath

    path = (path === '/' ? '' : path) + '/' + name
    const speedo = speedometer()
    let speed = 0
    let written = 0

    // Set up a passthrough stream to track stats.
    const passthrough = through(function (chunk, enc, next) {
      written += chunk.length
      speed = speedo(chunk.length)
      this.push(chunk)
      next()
    })

    // The actual streaming file reader.
    const reader = fileReader(file)

    // The write stream to the backend.
    const ws = await api.hyperdrive.createWriteStream(key, path)
github arso-project / archipel / packages / app / src / features / fs / UploadFile.js View on Github external
async uploadFile (file, i) {
    this.setState({ files: updateAt(this.state.files, i, { pending: true }) })
    const { dir, core } = this.props
    const { name } = file
    const path = (dir === '/' ? '' : dir) + '/' + name
    const speedo = speedometer()
    let speed = 0
    let written = 0
    const update = () => {
      // todo: rerender only if state acually changed.
      this.setState({ files: updateAt(this.state.files, i, { written, speed }) })
    }
    let debounce = setInterval(update, 200)
    const passthrough = through((chunk, enc, next) => {
      written += chunk.length
      speed = speedo(chunk.length)
      next()
    })
    const reader = fileReader(file)
    pump(reader, passthrough)

    const key = this.props.archive
github arso-project / archipel / packages / drive / frontend / UploadFile.js View on Github external
async uploadFile (file, i) {
    this.setState({ files: updateAt(this.state.files, i, { pending: true }) })
    const { dir, core } = this.props
    let { name, webkitRelativePath } = file
    if (this.state.uploadDir) name = webkitRelativePath

    const path = (dir === '/' ? '' : dir) + '/' + name
    const speedo = speedometer()
    let speed = 0
    let written = 0
    const update = () => {
      // todo: rerender only if state acually changed.
      this.setState({ files: updateAt(this.state.files, i, { written, speed }) })
    }
    let debounce = setInterval(update, 200)
    const passthrough = through((chunk, enc, next) => {
      written += chunk.length
      speed = speedo(chunk.length)
      next()
    })
    const reader = fileReader(file)
    pump(reader, passthrough)

    const key = this.props.archive
github beakerbrowser / beaker / app / builtin-pages / com / hypercore-stats.js View on Github external
export default function Stats (emitter, { archiveInfo, onToggleServing }) {
  if (!(this instanceof Stats)) return new Stats(emitter)

  this.emitter = emitter
  this.archiveInfo = archiveInfo
  this.uploadSpeed = speedometer()
  this.downloadSpeed = speedometer()
  this.onToggleServing = onToggleServing

  this.onUpdatePeers = ({ key, peers }) => {
    if (key === archiveInfo.key) {
      this.archiveInfo.peers = peers
      this.updateActives()
    }
  }
  this.onDownload = ({ key, index, bytes }) => {
    if (key === archiveInfo.key) {
      this.downloadSpeed(bytes)
      this.updateActives()
    }
  }
  this.onUpload = ({ key, index, bytes }) => {

speedometer

simple speed measurement in javascript

MIT
Latest version published 6 years ago

Package Health Score

53 / 100
Full package analysis

Popular speedometer functions