#321·windows95

Export HDA into img file

Author: mmaciolaCreated Feb 15, 2025Updated Sep 9, 2026

It is definitely necessary to be able to export files out from this emulator. Currently windows95.img works one way only and state-v3.bin is not readable to extract files.

We need a function that will update the img file or understand why this is problematic.

My current attempts:

  /**
   * Save the emulator's modified disk image to disk.
   */
  private async saveDiskImage(): Promise<void> {
    const { emulator } = this.state;
    const imgPath = (await getStatePath()).replace('.bin', '.img');

    console.log(`saveDiskImage into:` + imgPath);

    if (!emulator || !emulator.disk_images || !emulator.disk_images.hda) {
      console.log(`saveDiskImage: No disk image present`);
      return;
    }

    try {
      // Convert SyncBuffer to a Uint8Array
      const diskBuffer = new Uint8Array(emulator.disk_images.hda);
  
      // Save the raw buffer as an .img file
      await fs.outputFile(imgPath, Buffer.from(diskBuffer));
      console.log(`Disk image saved to ${imgPath}`);
    } catch (error) {
      console.warn(`saveDiskImage: Could not save disk image`, error);
      fs.appendFileSync('log.txt', `saveDiskImage: Could not save disk image: ${error.message}\n${error.stack}\n`);
    }
  }

As I understand this won't work, having blocks, we could:

  // Apply modified blocks
  const blockSize = 0x200;
  for (const { sector, data } of writtenBlocks) {
    const offset = sector * blockSize;
    if (offset + data.length <= diskBuffer.length) {
      data.copy(diskBuffer, offset);
    } else {
      console.warn(`saveDiskImage: Block at sector ${sector} exceeds disk size`);
    }
  }

Source: felixrieseberg/windows95