Skip to content

Commit

Permalink
feat: 增加API:uni.base64ToArrayBuffer、uni.arrayBufferToBase64
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed May 14, 2019
1 parent 53bd3bd commit 55bdf71
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@vue/test-utils": "^1.0.0-beta.25",
"babel-eslint": "^10.0.1",
"babylon": "^6.18.0",
"base64-arraybuffer": "^0.2.0",
"browserslist": "^4.4.2",
"caniuse-lite": "^1.0.30000940",
"chai": "^4.1.2",
Expand Down Expand Up @@ -59,8 +60,8 @@
"globals": {
"App": true,
"Page": true,
"Component": true,
"Behavior":true,
"Component": true,
"Behavior": true,
"getApp": true,
"getCurrentPages": true,
"plus": true,
Expand All @@ -76,8 +77,8 @@
"__PLATFORM__": true,
"__VERSION__": true,
"__GLOBAL__": true,
"__PLATFORM_TITLE__": true,
"__PLATFORM_PREFIX__":true
"__PLATFORM_TITLE__": true,
"__PLATFORM_PREFIX__": true
},
"rules": {
"no-tabs": 0,
Expand Down
26 changes: 13 additions & 13 deletions src/core/helpers/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
isFn
} from 'uni-shared'

const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/

const CONTEXT_API_RE = /^create|Manager$/

Expand Down Expand Up @@ -56,18 +56,18 @@ export function promisify (name, api) {
success: resolve,
fail: reject
}), ...params)
/* eslint-disable no-extend-native */
if (!Promise.prototype.finally) {
Promise.prototype.finally = function (callback) {
const promise = this.constructor
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
}
/* eslint-disable no-extend-native */
if (!Promise.prototype.finally) {
Promise.prototype.finally = function (callback) {
const promise = this.constructor
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
}
}
}))
}
}
}
11 changes: 11 additions & 0 deletions src/core/helpers/protocol/base64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const base64ToArrayBuffer = [{
name: 'base64',
type: String,
required: true
}]

export const arrayBufferToBase64 = [{
name: 'arrayBuffer',
type: [ArrayBuffer, Uint8Array],
required: true
}]
4 changes: 4 additions & 0 deletions src/core/service/api/base64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { encode, decode } from 'base64-arraybuffer'

export const base64ToArrayBuffer = decode
export const arrayBufferToBase64 = encode

0 comments on commit 55bdf71

Please sign in to comment.