Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "etcher-sdk in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'etcher-sdk' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

// 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)
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,
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',
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: [],
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',
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
/**
 * @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
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
}

    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)
        })
      })
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)

Is your System Free of Underlying Vulnerabilities?
Find Out Now