How to use the etcher-sdk.sourceDestination function in etcher-sdk

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 / 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)
github balena-io / etcher / lib / shared / supported-formats.js View on Github external
exports.getCompressedExtensions = () => {
  const result = []
  for (const [ mimetype, cls ] of sdk.sourceDestination.SourceDestination.mimetypes.entries()) {
    if (cls.prototype instanceof sdk.sourceDestination.CompressedSource) {
      const extension = mime.extension(mimetype)
      if (extension) {
        result.push(extension)
      }
    }
  }
  return result
}
github balena-io / etcher / lib / shared / supported-formats.js View on Github external
exports.getNonCompressedExtensions = () => {
  return sdk.sourceDestination.SourceDestination.imageExtensions
}

etcher-sdk

Etcher SDK

Apache-2.0
Latest version published 2 months ago

Package Health Score

64 / 100
Full package analysis