• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taichunmin / chameleon-ultra.js / 16902739519

12 Aug 2025 08:00AM UTC coverage: 68.124% (-1.1%) from 69.192%
16902739519

push

github

web-flow
Add support 9 new cmds (#204)

504 of 658 branches covered (76.6%)

Branch coverage included in aggregate %.

415 of 589 new or added lines in 10 files covered. (70.46%)

9 existing lines in 3 files now uncovered.

2815 of 4214 relevant lines covered (66.8%)

2958829.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/plugin/DfuZip.ts
1
import { Buffer } from '@taichunmin/buffer'
×
2
import JSZip from 'jszip'
×
3
import * as _ from 'lodash-es'
×
4
import { setObject } from '../iifeExportHelper'
×
5
import { type DfuImage, type DfuImageType, type DfuManifest } from '../types'
6

7
export default class DfuZip {
×
NEW
8
  #appImage?: DfuImage | null
×
NEW
9
  #baseImage?: DfuImage | null
×
NEW
10
  #gitVersion?: string | null
×
UNCOV
11
  #manifest: DfuManifest | null = null
×
NEW
12
  #zip: JSZip | null = null
×
NEW
13
  readonly #buf: Buffer
×
14

15
  constructor (buf: Buffer) {
×
16
    this.#buf = buf
×
17
  }
×
18

19
  async getManifest (): Promise<DfuManifest> {
×
NEW
20
    this.#zip ??= await JSZip.loadAsync(this.#buf)
×
NEW
21
    this.#manifest ??= await (async () => {
×
NEW
22
      const manifestJson = await this.#zip?.file('manifest.json')?.async('string')
×
23
      if (_.isNil(manifestJson)) throw new Error('Unable to find manifest, is this a proper DFU package?')
×
NEW
24
      return JSON.parse(manifestJson).manifest
×
NEW
25
    })()
×
26
    return this.#manifest as DfuManifest
×
27
  }
×
28

NEW
29
  async getFirstImageFile (types: DfuImageType[]): Promise<DfuImage | null> {
×
30
    const manifest = await this.getManifest()
×
31
    for (const type of types) {
×
32
      const image = manifest[type]
×
33
      if (_.isNil(image)) continue
×
34
      const [header, body] = await Promise.all(_.map([image.dat_file, image.bin_file], async file => {
×
35
        const u8 = await this.#zip?.file(file)?.async('uint8array')
×
36
        if (_.isNil(u8)) throw new Error(`Failed to read ${file} from DFU package`)
×
37
        return Buffer.fromView(u8)
×
38
      }))
×
39
      return { type, header, body }
×
40
    }
×
41
    return null
×
42
  }
×
43

44
  async getBaseImage (): Promise<DfuImage | null> {
×
NEW
45
    if (this.#baseImage === undefined) this.#baseImage = await this.getFirstImageFile(['softdevice', 'bootloader', 'softdevice_bootloader'])
×
NEW
46
    return this.#baseImage
×
UNCOV
47
  }
×
48

49
  async getAppImage (): Promise<DfuImage | null> {
×
NEW
50
    if (this.#appImage === undefined) this.#appImage = await this.getFirstImageFile(['application'])
×
NEW
51
    return this.#appImage
×
UNCOV
52
  }
×
53

54
  async getGitVersion (): Promise<string | null> {
×
NEW
55
    if (this.#gitVersion === undefined) {
×
NEW
56
      const image = await this.getAppImage()
×
57
      // eslint-disable-next-line no-control-regex
NEW
58
      this.#gitVersion = image?.body.toString('utf8').match(/\x00(v\d+(?:\.\d+)*[\w-]*)\x00/)?.[1] ?? null
×
NEW
59
    }
×
NEW
60
    return this.#gitVersion
×
61
  }
×
62
}
×
63

64
setObject(globalThis, ['ChameleonUltraJS', 'DfuZip'], DfuZip)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc