扫一扫
This commit is contained in:
@@ -50,6 +50,7 @@ export class BasicConstant {
|
||||
static readonly cancelRes = BasicConstant.urlExpert+'cancelRes'
|
||||
static readonly caseDetail = BasicConstant.urlExpert+'caseDetail'
|
||||
static readonly getFollowUp = BasicConstant.urlExpert+'getFollowUp'
|
||||
static readonly sendWebsocketMsg = BasicConstant.wxUrl+'watchlive/sendWebsocketMsg'
|
||||
static readonly deleteFollowUp = BasicConstant.urlExpert+'deleteFollowUp'
|
||||
static readonly addFollowUps = BasicConstant.urlExpert+'addFollowUps'
|
||||
static readonly addFollowUp = BasicConstant.urlExpert+'addFollowUp'
|
||||
@@ -142,5 +143,7 @@ export class BasicConstant {
|
||||
//聊天类型普通聊天与公益咨询
|
||||
static readonly general = "general";
|
||||
static readonly consult = "consult";
|
||||
|
||||
static readonly ExpertAesKey = 'deoep09_klodLdAo'
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import { buffer, util } from '@kit.ArkTS';
|
||||
|
||||
export const base = new util.Base64Helper();
|
||||
|
||||
const kBase64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
const kBase64PaddingChar = '=';
|
||||
|
||||
export class AESEncryptionDecryption {
|
||||
|
||||
// 字节流转成可理解的字符串
|
||||
@@ -111,5 +114,98 @@ export class AESEncryptionDecryption {
|
||||
console.info(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 解密
|
||||
static async aes128Decrypt(data: Uint8Array, key: string): Promise<Uint8Array> {
|
||||
try {
|
||||
// 创建对称密钥生成器
|
||||
const symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES128');
|
||||
// 创建加密解密工具
|
||||
const cipher = cryptoFramework.createCipher('AES128|ECB|PKCS7');
|
||||
// 将字符串密钥转换为DataBlob格式
|
||||
const keyBlob: cryptoFramework.DataBlob = {
|
||||
data: new Uint8Array(new util.TextEncoder().encodeInto(key))
|
||||
};
|
||||
// 生成对称密钥
|
||||
const symKey = await symKeyGenerator.convertKey(keyBlob);
|
||||
// 初始化解密模式
|
||||
await cipher.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null);
|
||||
// 执行解密
|
||||
const decryptData = await cipher.doFinal({ data: data });
|
||||
return decryptData.data;
|
||||
} catch (error) {
|
||||
console.error("AES解密过程中出错:", JSON.stringify(error));
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
//加密
|
||||
static async aes128Encrypt(data: Uint8Array, key: string): Promise<Uint8Array> {
|
||||
const algorithm = 'AES128|ECB|PKCS7';
|
||||
try {
|
||||
const symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES128');
|
||||
if (!symKeyGenerator) {
|
||||
console.error('创建密钥生成器失败')
|
||||
}
|
||||
const textEncoder = new util.TextEncoder();
|
||||
const keyData: Uint8Array = textEncoder.encodeInto(key);
|
||||
const keyBlob: cryptoFramework.DataBlob = { data: keyData };
|
||||
const symKey = await symKeyGenerator.convertKey(keyBlob);
|
||||
if (!symKey) {
|
||||
console.error('密钥转换失败')
|
||||
}
|
||||
const cipher = cryptoFramework.createCipher(algorithm)
|
||||
if (!cipher) {
|
||||
console.error('创建加密器失败')
|
||||
}
|
||||
await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null);
|
||||
const encryptResult = await cipher.doFinal({ data });
|
||||
return encryptResult.data;
|
||||
} catch (error) {
|
||||
console.error(`AES加密错误: ${JSON.stringify(error)}`);
|
||||
const emptyBuffer = new Uint8Array(0);
|
||||
return emptyBuffer
|
||||
}
|
||||
}
|
||||
|
||||
static customBase64Encode(data: Uint8Array): string {
|
||||
if (!data || data.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const inputLength = data.length;
|
||||
const maxLength = Math.floor((inputLength + 2) / 3) * 4;
|
||||
|
||||
const resultChars: string[] = [];
|
||||
let srcIndex = 0;
|
||||
|
||||
while (inputLength - srcIndex >= 3) {
|
||||
const byte1 = data[srcIndex++] & 0xFF;
|
||||
const byte2 = data[srcIndex++] & 0xFF;
|
||||
const byte3 = data[srcIndex++] & 0xFF;
|
||||
|
||||
resultChars.push(kBase64EncodeChars.charAt(byte1 >>> 2));
|
||||
resultChars.push(kBase64EncodeChars.charAt(((byte1 & 0x03) << 4) | (byte2 >>> 4)));
|
||||
resultChars.push(kBase64EncodeChars.charAt(((byte2 & 0x0F) << 2) | (byte3 >>> 6)));
|
||||
resultChars.push(kBase64EncodeChars.charAt(byte3 & 0x3F));
|
||||
}
|
||||
|
||||
if (inputLength - srcIndex > 0) {
|
||||
const byte1 = data[srcIndex++] & 0xFF;
|
||||
resultChars.push(kBase64EncodeChars.charAt(byte1 >>> 2));
|
||||
|
||||
if (inputLength - srcIndex === 0) {
|
||||
resultChars.push(kBase64EncodeChars.charAt((byte1 & 0x03) << 4));
|
||||
resultChars.push(kBase64PaddingChar);
|
||||
resultChars.push(kBase64PaddingChar);
|
||||
} else {
|
||||
const byte2 = data[srcIndex] & 0xFF;
|
||||
resultChars.push(kBase64EncodeChars.charAt(((byte1 & 0x03) << 4) | (byte2 >>> 4)));
|
||||
resultChars.push(kBase64EncodeChars.charAt((byte2 & 0x0F) << 2));
|
||||
resultChars.push(kBase64PaddingChar);
|
||||
}
|
||||
}
|
||||
|
||||
return resultChars.join('');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import { i18n } from '@kit.LocalizationKit';
|
||||
|
||||
export class CharUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 判断字符串char是否是数字
|
||||
* @param char
|
||||
* @returns
|
||||
*/
|
||||
static isDigit(char: string): boolean {
|
||||
return i18n.Unicode.isDigit(char);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串char是否是字母
|
||||
* @param char
|
||||
* @returns
|
||||
*/
|
||||
static isLetter(char: string): boolean {
|
||||
return i18n.Unicode.isLetter(char);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串char是否是小写字母
|
||||
* @param char
|
||||
* @returns
|
||||
*/
|
||||
static isLowerCase(char: string): boolean {
|
||||
return i18n.Unicode.isLowerCase(char);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串char是否是大写字母
|
||||
* @param char
|
||||
* @returns
|
||||
*/
|
||||
static isUpperCase(char: string): boolean {
|
||||
return i18n.Unicode.isUpperCase(char);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串char是否是空格符
|
||||
* @param char
|
||||
* @returns
|
||||
*/
|
||||
static isSpaceChar(char: string): boolean {
|
||||
return i18n.Unicode.isSpaceChar(char);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串char是否是空白符
|
||||
* @param char
|
||||
* @returns
|
||||
*/
|
||||
static isWhitespace(char: string): boolean {
|
||||
return i18n.Unicode.isWhitespace(char);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串char是否是从右到左语言的字符
|
||||
* @param char
|
||||
* @returns
|
||||
*/
|
||||
static isRTL(char: string): boolean {
|
||||
return i18n.Unicode.isRTL(char);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串char是否是表意文字
|
||||
* @param char
|
||||
* @returns
|
||||
*/
|
||||
static isIdeograph(char: string): boolean {
|
||||
return i18n.Unicode.isIdeograph(char);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否空白符 空白符包括空格、制表符、全角空格和不间断空格
|
||||
* @param c
|
||||
* @returns
|
||||
*/
|
||||
static isBlankChar(c: number): boolean {
|
||||
return CharUtil.isWhitespace(c.toString())
|
||||
|| CharUtil.isSpaceChar(c.toString())
|
||||
|| c === 0xFEFF || c === 0x202A || c === 0x0000;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断字符是否位于ASCII范围内(其中0-31是控制字符,32-127表示从A到Z的字母字符)
|
||||
* @param char 字符
|
||||
* @returns
|
||||
*/
|
||||
static isAscii(char: string): boolean {
|
||||
if (char.length === 1) { //确保输入的是单个字符
|
||||
return char.charCodeAt(0) < 128;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { detectBarcode, generateBarcode, scanBarcode, scanCore } from '@kit.ScanKit';
|
||||
import { image } from '@kit.ImageKit';
|
||||
import { AppUtil } from './AppUtil';
|
||||
// import { PhotoHelper } from '../photo/PhotoHelper';
|
||||
import { photoAccessHelper } from '@kit.MediaLibraryKit';
|
||||
|
||||
export class ScanUtil {
|
||||
/**
|
||||
* 调用默认界面扫码,使用Promise方式异步返回解码结果。
|
||||
* @param options
|
||||
* scanTypes 设置扫码类型,默认扫码ALL(全部码类型)。
|
||||
* enableMultiMode 是否开启多码识别,默认false。true:多码识别、false:单码识别。
|
||||
* enableAlbum 是否开启相册,默认true。true-开启相册扫码、false-关闭相册扫码。
|
||||
* @returns ScanResult 扫码结果:
|
||||
* scanType 码类型。
|
||||
* originalValue 码识别内容结果。
|
||||
* scanCodeRect 码识别位置信息。
|
||||
*/
|
||||
static startScanForResult(options?: scanBarcode.ScanOptions): Promise<scanBarcode.ScanResult> {
|
||||
if (options === undefined) {
|
||||
options = { scanTypes: [scanCore.ScanType.ALL], enableMultiMode: true, enableAlbum: false };
|
||||
}
|
||||
return scanBarcode.startScanForResult(AppUtil.getContext(), options); //启动扫码,拉起扫码界面
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 码图生成,使用Promise异步返回生成的码图。
|
||||
* @param content 码内容字符串
|
||||
* @param options 用于设置生成码图的参数:
|
||||
* scanType 码类型。
|
||||
* width 码图宽,单位:px。取值范围:[200, 4096]。
|
||||
* height 码图高,单位:px。取值范围:[200, 4096]。
|
||||
* margin 边距,单位:px,默认值为1,取值范围:[1, 10]。
|
||||
* level 纠错水平,默认值为LEVEL_H。此参数只在生成QR码时有效。
|
||||
* backgroundColor 生成码图背景颜色,HEX格式颜色,默认为白色(0xffffff)。
|
||||
* pixelMapColor 生成码图颜色,HEX格式颜色,默认为黑色(0x000000)。
|
||||
* @returns
|
||||
*/
|
||||
static generateBarcode(content: string, options?: generateBarcode.CreateOptions): Promise<image.PixelMap> {
|
||||
if (options === undefined) {
|
||||
options = { scanType: scanCore.ScanType.QR_CODE, height: 800, width: 800, margin: 5 };
|
||||
}
|
||||
return generateBarcode.createBarcode(content, options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过picker拉起图库并选择图片,并调用图片识码
|
||||
* @param options
|
||||
* @returns
|
||||
*/
|
||||
// static async onPickerScanForResult(options?: scanBarcode.ScanOptions): Promise<Array<scanBarcode.ScanResult>> {
|
||||
// const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
|
||||
// photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
|
||||
// photoSelectOptions.maxSelectNumber = 1; //单选
|
||||
// photoSelectOptions.isPhotoTakingSupported = true; //支持拍照。
|
||||
// photoSelectOptions.isEditSupported = false;
|
||||
// photoSelectOptions.isOriginalSupported = false;
|
||||
// let uris = await PhotoHelper.select(photoSelectOptions);
|
||||
// return ScanUtil.onDetectBarCode(uris[0], options);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 调用图片识码,使用Promise方式异步返回识码结果。
|
||||
* @param uri 图片路径。
|
||||
* @param options
|
||||
* scanTypes 设置扫码类型,默认扫码ALL(全部码类型)。
|
||||
* enableMultiMode 是否开启多码识别,默认false。true:多码识别、false:单码识别。
|
||||
* enableAlbum 是否开启相册,默认true。true-开启相册扫码、false-关闭相册扫码。
|
||||
* @returns ScanResult 扫码结果:
|
||||
* scanType 码类型。
|
||||
* originalValue 码识别内容结果。
|
||||
* scanCodeRect 码识别位置信息。
|
||||
*/
|
||||
static onDetectBarCode(uri: string, options?: scanBarcode.ScanOptions): Promise<Array<scanBarcode.ScanResult>> {
|
||||
const inputImage: detectBarcode.InputImage = { uri: uri };
|
||||
if (options === undefined) {
|
||||
options = { scanTypes: [scanCore.ScanType.ALL], enableMultiMode: true, enableAlbum: true };
|
||||
}
|
||||
return detectBarcode.decode(inputImage, options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断当前设备是否支持码能力
|
||||
* @returns
|
||||
*/
|
||||
static canIUseScan() {
|
||||
return canIUse('SystemCapability.Multimedia.Scan.ScanBarcode');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
import { CharUtil } from './CharUtil';
|
||||
import util from '@ohos.util';
|
||||
import { buffer } from '@kit.ArkTS';
|
||||
import { Base64Util } from './Base64Util';
|
||||
|
||||
export class StrUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 判断字符串是否为空(undefined、null)
|
||||
* @param str 被检测的字符串
|
||||
* @returns 是否为空
|
||||
*/
|
||||
static isNull(str: string | undefined | null): boolean {
|
||||
return str === undefined || str === null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否为非空。true为非空空,否则false
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
static isNotNull(str: string | undefined | null): boolean {
|
||||
return false === StrUtil.isNull(str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断字符串是否为空(undefined、null、字符串长度为0)
|
||||
* @param str 被检测的字符串
|
||||
* @return 是否为空
|
||||
*/
|
||||
static isEmpty(str: string | undefined | null): boolean {
|
||||
return str === undefined || str === null || str.length === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否为非空。true为非空空,否则false
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
static isNotEmpty(str: string | undefined | null): boolean {
|
||||
return false === StrUtil.isEmpty(str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断字符串是否为空和空白符(空白符包括空格、制表符、全角空格和不间断空格)。true为空,否则false
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
static isBlank(str: string | undefined | null): boolean {
|
||||
let length: number = 0;
|
||||
if ((str === undefined) || (str === null) || ((length = str.length) === 0)) {
|
||||
return true;
|
||||
}
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (false == CharUtil.isBlankChar(str.charCodeAt(i))) {
|
||||
return false; //只要有一个非空字符即为非空字符串
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否为非空和空白符(空白符包括空格、制表符、全角空格和不间断空格)true为非空,否则false
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
static isNotBlank(str: string | undefined | null): boolean {
|
||||
return false === StrUtil.isBlank(str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 格式化字符串
|
||||
* @param source
|
||||
* @param defaultValue
|
||||
* @returns
|
||||
*/
|
||||
static toStr(source: string | null | undefined, defaultValue = ""): string {
|
||||
if (source === null || source === undefined) {
|
||||
return defaultValue;
|
||||
}
|
||||
return String(source);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 替换字符串中匹配的正则为给定的字符串
|
||||
* @param str 待替换的字符串
|
||||
* @param pattern 要匹配的内容正则或字符串
|
||||
* @param replaceValue 替换的内容
|
||||
* @returns
|
||||
*/
|
||||
static replace(str: string, pattern: RegExp | string, replaceValue: string = ''): string {
|
||||
return str.replace(pattern, replaceValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换字符串中所有匹配的正则为给定的字符串
|
||||
* @param str 待替换的字符串
|
||||
* @param pattern 要匹配的内容正则或字符串
|
||||
* @param replaceValue 替换的内容
|
||||
* @returns 返回替换后的字符串
|
||||
*/
|
||||
static replaceAll(str: string, pattern: RegExp | string, replaceValue: string = ''): string {
|
||||
return str.replaceAll(pattern, replaceValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否以给定的字符串开头
|
||||
* @param string 要检索的字符串
|
||||
* @param target 要检索字符
|
||||
* @param position 检索的位置
|
||||
* @returns
|
||||
*/
|
||||
static startsWith(string: string = '', target: string, position: number = 0): boolean {
|
||||
return string.startsWith(target, position);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断字符串是否以给定的字符串结尾
|
||||
* @param str 要检索的字符串
|
||||
* @param target 要检索字符
|
||||
* @param position 检索的位置
|
||||
* @returns
|
||||
*/
|
||||
static endsWith(str: string = '', target: string, position: number = str.length): boolean {
|
||||
return str.endsWith(target, position);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将字符串重复指定次数
|
||||
* @param str 要重复的字符串
|
||||
* @param n 重复的次数
|
||||
* @returns
|
||||
*/
|
||||
static repeat(str: string = '', n: number = 1): string {
|
||||
return str.repeat(n);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将整个字符串转换为小写
|
||||
* @param str 要转换的字符串
|
||||
* @returns 返回小写的字符串
|
||||
*/
|
||||
static toLower(str: string = ''): string {
|
||||
return str.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将整个字符串转换为大写
|
||||
* @param str 要转换的字符串
|
||||
* @returns 返回小写的字符串
|
||||
*/
|
||||
static toUpper(str: string = ''): string {
|
||||
return str.toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将字符串首字母转换为大写,剩下为小写
|
||||
* @param str 待转换的字符串
|
||||
* @returns 转换后的
|
||||
*/
|
||||
static capitalize(str: string = ''): string {
|
||||
if (StrUtil.isNotEmpty(str)) {
|
||||
const firstChar = str.charAt(0).toUpperCase();
|
||||
const restChars = str.slice(1).toLowerCase();
|
||||
return firstChar + restChars;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断两个传入的数值或者是字符串是否相等
|
||||
* @param source
|
||||
* @param target
|
||||
* @returns
|
||||
*/
|
||||
static equal(source: string | number, target: string | number): boolean {
|
||||
return source === target;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断两个传入的数值或者是字符串是否不相等
|
||||
* @param source
|
||||
* @param target
|
||||
* @returns
|
||||
*/
|
||||
static notEqual(source: string | number, target: string | number): boolean {
|
||||
return false === StrUtil.equal(source, target);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字符串转Uint8Array
|
||||
* @param src 字符串
|
||||
* @returns Uint8Array
|
||||
*/
|
||||
public static strToUint8Array(src: string, encoding: buffer.BufferEncoding = 'utf-8'): Uint8Array {
|
||||
const textEncoder = new util.TextEncoder(encoding);
|
||||
const result = textEncoder.encodeInto(src);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uint8Array转字符串
|
||||
* @param src Uint8Array
|
||||
* @returns 字符串
|
||||
*/
|
||||
static unit8ArrayToStr(src: Uint8Array, encoding: buffer.BufferEncoding = 'utf-8'): string {
|
||||
const textDecoder = util.TextDecoder.create(encoding, { ignoreBOM: true })
|
||||
const result = textDecoder.decodeToString(src, { stream: true });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 16进制字符串转换unit8Array
|
||||
* @param hexStr
|
||||
* @returns
|
||||
*/
|
||||
static strToHex(hexStr: string): Uint8Array {
|
||||
return new Uint8Array(buffer.from(hexStr, 'hex').buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 16进制unit8Array转字符串
|
||||
* @param arr
|
||||
* @returns
|
||||
*/
|
||||
static hexToStr(arr: Uint8Array): string {
|
||||
return buffer.from(arr).toString('hex');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bytes转字符串
|
||||
* @param bytes
|
||||
* @returns
|
||||
*/
|
||||
public static bytesToStr(bytes: Uint8Array): string {
|
||||
let str = ""
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
str += String.fromCharCode(bytes[i]);
|
||||
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转Bytes
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
public static strToBytes(str: string): Uint8Array {
|
||||
let bytes: number[] = new Array();
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
bytes.push(str.charCodeAt(i))
|
||||
}
|
||||
return new Uint8Array(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64字符串转字符串
|
||||
* @param base64Str Base64字符串
|
||||
* @returns
|
||||
*/
|
||||
static base64ToStr(base64Str: string): string {
|
||||
const uint8Array = Base64Util.decodeSync(base64Str);
|
||||
const result = StrUtil.unit8ArrayToStr(uint8Array);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字符串转ArrayBuffer
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
static strToBuffer(src: string, encoding: buffer.BufferEncoding = 'utf-8'): ArrayBuffer {
|
||||
const buf = buffer.from(src, encoding);
|
||||
return buf.buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayBuffer转字符串
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
static bufferToStr(src: ArrayBuffer, encoding: buffer.BufferEncoding = 'utf-8'): string {
|
||||
const buf = buffer.from(src);
|
||||
const result = buf.toString(encoding);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ArrayBuffer转Uint8Array
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
static bufferToUint8Array(src: ArrayBuffer): Uint8Array {
|
||||
return new Uint8Array(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uint8Array转ArrayBuffer
|
||||
* @param str
|
||||
* @returns
|
||||
*/
|
||||
static unit8ArrayToBuffer(src: Uint8Array): ArrayBuffer {
|
||||
// return buffer.from(src).buffer;
|
||||
return src.buffer as ArrayBuffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取系统错误码对应的详细信息
|
||||
* @param errno 错误码
|
||||
* @returns
|
||||
*/
|
||||
static getErrnoToString(errno: number): string {
|
||||
return util.errnoToString(errno);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user