-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from yjl9903/main
fix: remove circular deps
- Loading branch information
Showing
3 changed files
with
26 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const decodeMessageData = (data: any) => { | ||
if (typeof data == 'string') { | ||
return data | ||
} else if (data instanceof Uint8Array || data instanceof ArrayBuffer) { | ||
return new TextDecoder().decode(data) | ||
} else if (data.buffer instanceof ArrayBuffer) { | ||
return new TextDecoder().decode(data.buffer) | ||
} else if (Array.isArray(data)) { | ||
const out: string[] = [] | ||
const decoder = new TextDecoder() | ||
for (const chunk of data) { | ||
if (typeof chunk == 'string') { | ||
out.push(chunk) | ||
} else if (chunk instanceof Uint8Array || chunk instanceof ArrayBuffer) { | ||
out.push(decoder.decode(chunk)) | ||
} else if (chunk.buffer instanceof ArrayBuffer) { | ||
out.push(decoder.decode(chunk.buffer)) | ||
} | ||
} | ||
return out.join('') | ||
} else { | ||
throw new Error('[maria2 error] Message data cannot be decoded') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters