Skip to content

Commit

Permalink
refactor: update type definitions for ArrayBuffer and related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleSound committed Feb 3, 2025
1 parent 37b15af commit 9f97fa8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import antfu from '@antfu/eslint-config'
import nuxt from './.nuxt/eslint.config.mjs'

export default nuxt(
antfu(
await antfu(
{
unocss: true,
formatters: true,
Expand Down
10 changes: 5 additions & 5 deletions utils/slicing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export type SliceData = [
chunk: string,
]

function arrayBufferToBase64(buffer: ArrayBuffer): string {
function arrayBufferToBase64(buffer: ArrayBufferLike): string {
return fromUint8Array(new Uint8Array(buffer))
}

function base64ToArrayBuffer(str: string): ArrayBuffer {
function base64ToArrayBuffer(str: string): ArrayBufferLike {
return toUint8Array(str).buffer
}

export function slice(input: string | ArrayBuffer, chunkSize = 256): SliceData[] {
export function slice(input: string | ArrayBufferLike, chunkSize = 256): SliceData[] {
const hash = getHash(input)
const isBinary = typeof input !== 'string'
const processed = typeof input !== 'string'
Expand All @@ -39,13 +39,13 @@ export function slice(input: string | ArrayBuffer, chunkSize = 256): SliceData[]
)
}

export function merge(slices: SliceData[]): string | ArrayBuffer {
export function merge(slices: SliceData[]): string | ArrayBufferLike {
const merged = slices.map(i => i[4]).join('')
const decompressed = decompressFromBase64(merged)
const targetHash = slices[0]![0]
const isBinary = slices[0]![3] === 0

const data: string | ArrayBuffer = isBinary
const data: string | ArrayBufferLike = isBinary
? base64ToArrayBuffer(decompressed)
: decompressed

Expand Down

0 comments on commit 9f97fa8

Please sign in to comment.