| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 2 年前 | ||
| 1 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 1 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 |
@protobufjs/base64
简介
@protobufjs/base64 一个用于数字数组的最小化的base64实现。
下载安装
ohpm install @protobufjs/base64
OpenHarmony ohpm环境配置等更多内容,请参考 如何安装OpenHarmony ohpm包 。
使用说明
引用及使用
1、引入依赖
import { length, encode, decode, test } from '@protobufjs/base64'
2、加密Uint8Array
let test="openharmony"
const textEncoder = new util.TextEncoder()
let uint8Array = textEncoder.encodeInto(test)
let result= encode(uint8Array, 0, uint8Array.length)
2、解码base64编码的字符串
let test="openharmony"
const textEncoder = new util.TextEncoder()
let uint8Array = textEncoder.encodeInto(test)
let encodeStr= encode(uint8Array, 0, uint8Array.length)
let decodeUint8Array = new Uint8Array(length(encodeStr))
decode(encodeStr, decodeUint8Array, 0)
3、计算一个base64编码字符串的字节长度
let test="openharmony"
const textEncoder = new util.TextEncoder()
let uint8Array = textEncoder.encodeInto(test)
let encodeStr = encode(uint8Array, 0, uint8Array.length)
let byteLength= length(encodeStr)
3、测试指定的字符串是否为base64编码
test("123435")
test("5L2g5aW9")
接口说明
-
计算一个base64编码字符串的字节长度
length(string: string): number -
将一个buffer编码为base64编码的字符串
encode(buffer: Uint8Array, start: number, end: number): string -
将一个base64编码的字符串解码成一个buffer
decode(string: string, buffer: Uint8Array, offset: number): number -
测试指定的字符串是否为base64编码
test(string: string): boolean
约束与限制
在下述版本验证通过:
- DevEco Studio 版本:4.1 Canary(4.1.3.317),OpenHarmony SDK:API11 (4.1.0.36)
目录结构
|---- ohos_entities
| |---- entry # 示例代码文件夹
| |---- src
| |---- ohosTest
| |---- ets
| |---- test
| |---- Ability.test.ets # 单元测试
| |---- README_zh.md # 安装使用方法
| |---- README.md # 安装使用方法
贡献代码
使用过程中发现任何问题都可以提 Issue 给组件,当然,也非常欢迎发 PR共建。
开源协议
本项目基于 BSD License,请自由地享受和参与开源。