Skip to content

Commit

Permalink
perf: use TextDecoder to transform the Uint8Array to String
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou committed Sep 5, 2024
1 parent 6414089 commit 847e37c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/webcams/streamers/Mjpegstreamer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export default class Mjpegstreamer extends Mixins(BaseMixin, WebcamMixin) {
let headers = ''
let contentLength = -1
let imageBuffer: Uint8Array = new Uint8Array(0)
const decoder = new TextDecoder('latin1');
let bytesRead = 0
let done: boolean | null = null
Expand Down Expand Up @@ -236,7 +237,7 @@ export default class Mjpegstreamer extends Mixins(BaseMixin, WebcamMixin) {
// we're done reading the jpeg. Time to render it.
if (this.image) {
this.image.src = 'data:image/jpeg;base64,' + btoa(Array.from(imageBuffer).map(byte => String.fromCharCode(byte)).join(''))
this.image.src = 'data:image/jpeg;base64,' + btoa(decoder.decode(imageBuffer))
}
this.frames++
contentLength = 0
Expand Down

0 comments on commit 847e37c

Please sign in to comment.