Skip to content

Commit

Permalink
chore: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
septs committed Jan 27, 2021
1 parent c56456a commit 3dcd1be
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type EncodeImageOptions = {

export async function encodeImage(buf: string | ArrayBuffer, options: EncodeImageOptions) {
const { template } = options
const _buf = typeof buf === 'string' ? decodeArrayBuffer(buf) : buf
buf = typeof buf === 'string' ? decodeArrayBuffer(buf) : buf
const mask = await getMaskBuf(template === 'v2' || template === 'v4' ? template : 'transparent')
const encodedOptions: EncodeOptions = {
...defaultOptions,
Expand All @@ -82,15 +82,15 @@ export async function encodeImage(buf: string | ArrayBuffer, options: EncodeImag
transformAlgorithm: TransformAlgorithm.FFT1D,
...options,
}
return encodeArrayBuffer(await encode(_buf, mask, encodedOptions))
return encodeArrayBuffer(await encode(buf, mask, encodedOptions))
}

type DecodeImageOptions = PartialRequired<Required<DecodeOptions>, 'pass'>

export async function decodeImage(buf: string | ArrayBuffer, options: DecodeImageOptions) {
const _buf = typeof buf === 'string' ? decodeArrayBuffer(buf) : buf
const _dimension = getDimension(_buf)
const preset = dimensionPreset.find((d) => isSameDimension(d, _dimension))
buf = typeof buf === 'string' ? decodeArrayBuffer(buf) : buf
const dimension = getDimension(buf)
const preset = dimensionPreset.find((d) => isSameDimension(d, dimension))
if (!preset) return ''
const _options: DecodeOptions = {
...defaultOptions,
Expand All @@ -99,10 +99,10 @@ export async function decodeImage(buf: string | ArrayBuffer, options: DecodeImag
...options,
}
try {
return await decode(_buf, await getMaskBuf(preset.mask), _options)
return await decode(buf, await getMaskBuf(preset.mask), _options)
} catch {
_options.version = AlgorithmVersion.V1
return decode(_buf, await getMaskBuf(preset.mask), _options)
return decode(buf, await getMaskBuf(preset.mask), _options)
}
}

Expand Down

0 comments on commit 3dcd1be

Please sign in to comment.