Skip to content

Commit f8a4836

Browse files
committed
refactor!: rename indiceSize to sliceSIze
1 parent 79fbfd2 commit f8a4836

File tree

8 files changed

+30
-17
lines changed

8 files changed

+30
-17
lines changed

packages/generate/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const generaterSvg = createGeneraterSVG(new Uint8Array(file.buffer))
4444

4545
const generaterANSI = createGeneraterANSI(new Uint8Array(file.buffer), {
4646
// Size of each data slice
47-
indicesSize: 250,
47+
sliceSize: 250,
4848
// Error correction level
4949
ecc: 'L',
5050
// Border width

packages/generate/src/base-generater.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function createGeneraterWithRender<Result, RenderOptions>(createRender: C
55
return (data: Uint8Array, options?: GeneraterBaseOptions<RenderOptions>) => {
66
const _options = Object.assign({}, GeneraterDefaultOptions, options)
77

8-
const encoder = createEncoder(data, _options.indicesSize, _options.compress)
8+
const encoder = createEncoder(data, _options.sliceSize, _options.compress)
99

1010
let _fountain: ReturnType<typeof encoder.fountain>
1111

packages/generate/src/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ export {
77

88
GeneraterDefaultOptions,
99
} from './shared'
10+
11+
export {
12+
appendFileHeaderMetaToBuffer,
13+
appendMetaToBuffer,
14+
readFileHeaderMetaFromBuffer,
15+
readMetaFromBuffer,
16+
} from 'luby-transform'

packages/generate/src/shared.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { blockToBinary, type EncodedBlock } from 'luby-transform'
44
export type CreateBlockRenderFn<Result, RenderOptions> = (renderOptions: GeneraterBaseOptions<RenderOptions>) => (block: EncodedBlock) => Result
55

66
export type GeneraterBaseOptions<RenderOptions> = {
7-
indicesSize?: number
7+
sliceSize?: number
88
compress?: boolean
99
urlPrefix?: string
1010
} & RenderOptions
1111

1212
export const GeneraterDefaultOptions = {
13-
indicesSize: 500,
13+
sliceSize: 500,
1414
urlPrefix: '',
1515
}
1616

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { expect, it } from 'vitest'
2+
import { createGeneraterQRCodeArray } from '../src/index'
23

3-
it.todo('should generate test', () => {
4-
expect(1).toBe(1)
4+
// it.todo('should generate test', () => {
5+
// expect(1).toBe(1)
6+
// })
7+
8+
it('generate boolean array', () => {
9+
const result = createGeneraterQRCodeArray(new Uint8Array(1).fill(23), 1000)
10+
expect(result).toMatchInlineSnapshot()
511
})

packages/luby-transform/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Creates a new `LtEncoder` instance for encoding data.
135135
#### Parameters
136136

137137
- `data` (`Uint8Array`): The raw data to be encoded.
138-
- `indicesSize` (`number`): The size of each block.
138+
- `sliceSize` (`number`): The size of each block.
139139
- `compress` (`boolean`, optional): Whether to compress the data. Defaults to `true`.
140140

141141
#### Returns

packages/luby-transform/src/decoder.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,19 @@ export class LtDecoder {
155155
return
156156
}
157157

158-
const indicesSize = this.meta.data.length
158+
const sliceSize = this.meta.data.length
159159
const blocks = this.decodedData as Uint8Array[]
160160
const decodedData = new Uint8Array(this.meta.bytes)
161161

162162
blocks.forEach((block, i) => {
163-
const start = i * indicesSize
164-
if (start + indicesSize > decodedData.length) {
163+
const start = i * sliceSize
164+
if (start + sliceSize > decodedData.length) {
165165
for (let j = 0; j < decodedData.length - start; j++) {
166166
decodedData[start + j] = block[j]!
167167
}
168168
}
169169
else {
170-
decodedData.set(block, i * indicesSize)
170+
decodedData.set(block, i * sliceSize)
171171
}
172172
})
173173

packages/luby-transform/src/encoder.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { EncodedBlock } from './shared'
22
import { deflate } from 'pako'
33
import { getChecksum } from './checksum'
44

5-
export function createEncoder(data: Uint8Array, indicesSize: number, compress = true): LtEncoder {
6-
return new LtEncoder(data, indicesSize, compress)
5+
export function createEncoder(data: Uint8Array, sliceSize: number, compress = true): LtEncoder {
6+
return new LtEncoder(data, sliceSize, compress)
77
}
88

99
export class LtEncoder {
@@ -15,21 +15,21 @@ export class LtEncoder {
1515

1616
constructor(
1717
public readonly data: Uint8Array,
18-
public readonly indicesSize: number,
18+
public readonly sliceSize: number,
1919
public readonly compress = true,
2020
) {
2121
this.compressed = compress ? deflate(data) : data
22-
this.indices = sliceData(this.compressed, indicesSize)
22+
this.indices = sliceData(this.compressed, sliceSize)
2323
this.k = this.indices.length
2424
this.checksum = getChecksum(this.data, this.k)
2525
this.bytes = this.compressed.length
2626
}
2727

2828
createBlock(indices: number[]): EncodedBlock {
29-
const data = new Uint8Array(this.indicesSize)
29+
const data = new Uint8Array(this.sliceSize)
3030
for (const index of indices) {
3131
const indicesIndex = this.indices[index]!
32-
for (let i = 0; i < this.indicesSize; i++) {
32+
for (let i = 0; i < this.sliceSize; i++) {
3333
data[i] = data[i]! ^ indicesIndex[i]!
3434
}
3535
}

0 commit comments

Comments
 (0)