How to use etcher-sdk - 10 common examples

To help you get started, we’ve selected a few etcher-sdk 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 balena-io / etcher / lib / gui / modules / child-writer.js View on Github external
// TODO: device should be destination
        device: destination.drive,
        error: errors.toJSON(error)
      })
    }

    const destinations = _.map(options.destinations, 'device')
    log(`Image: ${options.imagePath}`)
    log(`Devices: ${destinations.join(', ')}`)
    log(`Umount on success: ${options.unmountOnSuccess}`)
    log(`Validate on success: ${options.validateWriteOnSuccess}`)
    log(`Trim: ${options.trim}`)
    const dests = _.map(options.destinations, (destination) => {
      return new sdk.sourceDestination.BlockDevice(destination, options.unmountOnSuccess)
    })
    const source = new sdk.sourceDestination.File(options.imagePath, sdk.sourceDestination.File.OpenFlags.Read)
    try {
      const results = await writeAndValidate(
        source,
        dests,
        options.validateWriteOnSuccess,
        options.trim,
        onProgress,
        onFail
      )
      log(`Finish: ${results.bytesWritten}`)
      results.errors = _.map(results.errors, (error) => {
        return errors.toJSON(error)
      })
      ipc.of[IPC_SERVER_ID].emit('done', { results })
      await Bluebird.delay(DISCONNECT_DELAY)
      terminate(exitCode)
github balena-io / etcher / lib / gui / modules / child-writer.js View on Github external
const writeAndValidate = async (source, destinations, verify, trim, onProgress, onFail) => {
  let innerSource = await source.getInnerSource()
  if (trim && (await innerSource.canRead())) {
    innerSource = new sdk.sourceDestination.ConfiguredSource(
      innerSource,
      trim,

      // Create stream from file-disk (not source stream)
      true
    )
  }
  const { failures, bytesWritten } = await sdk.multiWrite.pipeSourceToDestinations(
    innerSource,
    destinations,
    onFail,
    onProgress,
    verify
  )
  const result = {
    bytesWritten,
github balena-io / etcher / lib / gui / app / pages / main / controllers / image-selection.js View on Github external
imagePath = await replaceWindowsNetworkDriveLetter(imagePath)
    } catch (error) {
      analytics.logException(error)
    }
    if (!supportedFormats.isSupportedImage(imagePath)) {
      const invalidImageError = errors.createUserError({
        title: 'Invalid image',
        description: messages.error.invalidImage(imagePath)
      })

      osDialog.showError(invalidImageError)
      analytics.logEvent('Invalid image', { path: imagePath })
      return
    }

    const source = new sdk.sourceDestination.File(imagePath, sdk.sourceDestination.File.OpenFlags.Read)
    try {
      const innerSource = await source.getInnerSource()
      const metadata = await innerSource.getMetadata()
      const partitionTable = await innerSource.getPartitionTable()
      if (partitionTable) {
        metadata.hasMBR = true
        metadata.partitions = partitionTable.partitions
      }
      metadata.path = imagePath
      // eslint-disable-next-line no-magic-numbers
      metadata.extension = path.extname(imagePath).slice(1)
      this.selectImage(metadata)
      $timeout()
    } catch (error) {
      const imageError = errors.createUserError({
        title: 'Error opening image',
github balena-io / etcher / lib / gui / app / app.js View on Github external
const prepareDrive = (drive) => {
    if (drive instanceof sdk.sourceDestination.BlockDevice) {
      return drive.drive
    } else if (drive instanceof sdk.sourceDestination.UsbbootDrive) {
      // This is a workaround etcher expecting a device string and a size
      drive.device = drive.usbDevice.portId
      drive.size = null
      drive.progress = 0
      drive.disabled = true
      drive.on('progress', (progress) => {
        updateDriveProgress(drive, progress)
      })
      return drive
    } else if (drive instanceof sdk.sourceDestination.DriverlessDevice) {
      const description = COMPUTE_MODULE_DESCRIPTIONS[drive.deviceDescriptor.idProduct] || 'Compute Module'
      return {
        device: `${usbIdToString(drive.deviceDescriptor.idVendor)}:${usbIdToString(drive.deviceDescriptor.idProduct)}`,
        displayName: 'Missing drivers',
        description,
        mountpoints: [],
github balena-io / etcher / lib / gui / app / app.js View on Github external
const prepareDrive = (drive) => {
    if (drive instanceof sdk.sourceDestination.BlockDevice) {
      return drive.drive
    } else if (drive instanceof sdk.sourceDestination.UsbbootDrive) {
      // This is a workaround etcher expecting a device string and a size
      drive.device = drive.usbDevice.portId
      drive.size = null
      drive.progress = 0
      drive.disabled = true
      drive.on('progress', (progress) => {
        updateDriveProgress(drive, progress)
      })
      return drive
    } else if (drive instanceof sdk.sourceDestination.DriverlessDevice) {
      const description = COMPUTE_MODULE_DESCRIPTIONS[drive.deviceDescriptor.idProduct] || 'Compute Module'
      return {
        device: `${usbIdToString(drive.deviceDescriptor.idVendor)}:${usbIdToString(drive.deviceDescriptor.idProduct)}`,
        displayName: 'Missing drivers',
github balena-io / etcher / lib / gui / app / modules / drive-scanner.js View on Github external
const adapters = [
  new sdk.scanner.adapters.BlockDeviceAdapter(includeSystemDrives)
]

// Can't use permissions.isElevated() here as it returns a promise and we need to set
// module.exports = scanner right now.
// eslint-disable-next-line no-magic-numbers
if ((process.platform !== 'linux') || (process.geteuid() === 0)) {
  adapters.push(new sdk.scanner.adapters.UsbbootDeviceAdapter())
}

if (process.platform === 'win32') {
  adapters.push(new sdk.scanner.adapters.DriverlessDeviceAdapter())
}

const scanner = new sdk.scanner.Scanner(adapters)

module.exports = scanner
github balena-io / etcher / lib / gui / app / modules / drive-scanner.js View on Github external
/**
 * @summary returns true if system drives should be shown
 * @function
 *
 * @returns {Boolean}
 *
 * @example
 * const shouldInclude = includeSystemDrives()
 */
const includeSystemDrives = () => {
  return settings.get('unsafeMode') && !settings.get('disableUnsafeMode')
}

const adapters = [
  new sdk.scanner.adapters.BlockDeviceAdapter(includeSystemDrives)
]

// Can't use permissions.isElevated() here as it returns a promise and we need to set
// module.exports = scanner right now.
// eslint-disable-next-line no-magic-numbers
if ((process.platform !== 'linux') || (process.geteuid() === 0)) {
  adapters.push(new sdk.scanner.adapters.UsbbootDeviceAdapter())
}

if (process.platform === 'win32') {
  adapters.push(new sdk.scanner.adapters.DriverlessDeviceAdapter())
}

const scanner = new sdk.scanner.Scanner(adapters)

module.exports = scanner
github balena-io / etcher / lib / gui / modules / child-writer.js View on Github external
const writeAndValidate = async (source, destinations, verify, trim, onProgress, onFail) => {
  let innerSource = await source.getInnerSource()
  if (trim && (await innerSource.canRead())) {
    innerSource = new sdk.sourceDestination.ConfiguredSource(
      innerSource,
      trim,

      // Create stream from file-disk (not source stream)
      true
    )
  }
  const { failures, bytesWritten } = await sdk.multiWrite.pipeSourceToDestinations(
    innerSource,
    destinations,
    onFail,
    onProgress,
    verify
  )
  const result = {
    bytesWritten,
    devices: {
      failed: failures.size,
      successful: destinations.length - failures.size
    },
    errors: []
  }
  for (const [ destination, error ] of failures) {
    error.device = destination.drive.device
github balena-io / etcher / lib / gui / app / components / file-selector / file-selector / file-selector.jsx View on Github external
}

    if (!supportedFormats.isSupportedImage(file.path)) {
      const invalidImageError = errors.createUserError({
        title: 'Invalid image',
        description: messages.error.invalidImage(file.path)
      })

      osDialog.showError(invalidImageError)
      analytics.logEvent('Invalid image', { path: file.path })
      return
    }

    debug('FileSelector:getImageMetadata', file)

    const source = new sdk.sourceDestination.File(file.path, sdk.sourceDestination.File.OpenFlags.Read)
    source.getInnerSource()
    .then((innerSource) => {
      return innerSource.getMetadata()
      .then((imageMetadata) => {
        debug('FileSelector:getImageMetadata', imageMetadata)
        imageMetadata.path = file.path
        imageMetadata.extension = path.extname(file.path).slice(1)
        return innerSource.getPartitionTable()
        .then((partitionTable) => {
          if (partitionTable !== undefined) {
            imageMetadata.hasMBR = true
            imageMetadata.partitions = partitionTable.partitions
          }
          return this.selectImage(imageMetadata)
        })
      })
github balena-io / etcher / lib / gui / modules / child-writer.js View on Github external
const dests = _.map(options.destinations, (destination) => {
      return new sdk.sourceDestination.BlockDevice(destination, options.unmountOnSuccess)
    })
    const source = new sdk.sourceDestination.File(options.imagePath, sdk.sourceDestination.File.OpenFlags.Read)

etcher-sdk

Etcher SDK

Apache-2.0
Latest version published 1 month ago

Package Health Score

66 / 100
Full package analysis