Showing
19 changed files
with
3757 additions
and
86 deletions
| @@ -15,7 +15,15 @@ | @@ -15,7 +15,15 @@ | ||
| 15 | <view class="text-df margin-bottom-xs text-blue">#{{post.eval_label}}</view> | 15 | <view class="text-df margin-bottom-xs text-blue">#{{post.eval_label}}</view> |
| 16 | <view class="grid col-3 grid-square" wx:if="{{enclosure.length>0}}"> | 16 | <view class="grid col-3 grid-square" wx:if="{{enclosure.length>0}}"> |
| 17 | <block wx:for="{{enclosure}}" wx:key="enclosure"> | 17 | <block wx:for="{{enclosure}}" wx:key="enclosure"> |
| 18 | - <view class="bg-image" style="background-image: url('{{item.url}}.lim.jpg')" catchtap="displayImage" data-index="{{index}}"> | 18 | + <view wx:if="{{!item.avinfo}}" class="bg-image" style="background-image: url('{{item.url}}')" catchtap="displayImage" data-index="{{index}}"> |
| 19 | + </view> | ||
| 20 | + <view wx:else class="bg-image" catchtap="displayImage" data-index="{{index}}"> | ||
| 21 | + <video | ||
| 22 | + class="videoBox" | ||
| 23 | + src="{{item.url}}" | ||
| 24 | + controls='{{false}}' | ||
| 25 | + enable-progress-gesture='{{false}}' | ||
| 26 | + /> | ||
| 19 | <view class="bg-image-video view" wx:if="{{item.avinfo}}"></view> | 27 | <view class="bg-image-video view" wx:if="{{item.avinfo}}"></view> |
| 20 | </view> | 28 | </view> |
| 21 | </block> | 29 | </block> |
miniprogram/components/tpupload/tpupload.js
0 → 100644
| 1 | +// components/tpupload/tpupload.js | ||
| 2 | +import util from '../../utils/util' | ||
| 3 | +import App from '../../utils/api' | ||
| 4 | +Component({ | ||
| 5 | + /** | ||
| 6 | + * 组件的属性列表 | ||
| 7 | + */ | ||
| 8 | + properties: { | ||
| 9 | + uploadDesc: String, | ||
| 10 | + tpKey: String, | ||
| 11 | + tpNum: Number, | ||
| 12 | + files: Array, | ||
| 13 | + }, | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 组件的初始数据 | ||
| 17 | + */ | ||
| 18 | + data: { | ||
| 19 | + files: [], | ||
| 20 | + filesHttps: [], | ||
| 21 | + token: '', | ||
| 22 | + }, | ||
| 23 | + lifetimes: { | ||
| 24 | + attached: function () {}, | ||
| 25 | + detached: function () {}, | ||
| 26 | + }, | ||
| 27 | + pageLifetimes: { | ||
| 28 | + show() { | ||
| 29 | + App.Qiniu.GetUploadToken().then(res => { | ||
| 30 | + let token = res.data.token | ||
| 31 | + this.setData({ | ||
| 32 | + token | ||
| 33 | + }) | ||
| 34 | + }) | ||
| 35 | + } | ||
| 36 | + }, | ||
| 37 | + /** | ||
| 38 | + * 组件的方法列表 | ||
| 39 | + */ | ||
| 40 | + methods: { | ||
| 41 | + // 删除图片或者视频 | ||
| 42 | + deleteFun(e) { | ||
| 43 | + var files = this.data.files; | ||
| 44 | + var that = this; | ||
| 45 | + var index = e.currentTarget.dataset.index; | ||
| 46 | + let filesHttps = this.data.filesHttps; | ||
| 47 | + util.deletelUpload(filesHttps[index].url, this.data.token, (res => { | ||
| 48 | + filesHttps.splice(index, 1) | ||
| 49 | + files.splice(index, 1) | ||
| 50 | + this.setData({ | ||
| 51 | + filesHttps, | ||
| 52 | + files | ||
| 53 | + }) | ||
| 54 | + })) | ||
| 55 | + that.triggerEvent('tpupload', { | ||
| 56 | + files, | ||
| 57 | + filesHttps | ||
| 58 | + }) | ||
| 59 | + }, | ||
| 60 | + // 预览图片 | ||
| 61 | + previewImg(e) { | ||
| 62 | + var index = e.currentTarget.dataset.index; | ||
| 63 | + var files = this.data.files; | ||
| 64 | + let arr = [] | ||
| 65 | + files.forEach(i => { | ||
| 66 | + arr.push(i.path) | ||
| 67 | + }) | ||
| 68 | + wx.previewImage({ | ||
| 69 | + current: files[index].path, | ||
| 70 | + urls: arr | ||
| 71 | + }) | ||
| 72 | + }, | ||
| 73 | + // 选择视频 上传视频 chooseMedia方法一次只能上传一个视频 | ||
| 74 | + uploadVideos() { | ||
| 75 | + var that = this; | ||
| 76 | + var files = that.data.files; | ||
| 77 | + wx.chooseMedia({ | ||
| 78 | + mediaType: ['video'], | ||
| 79 | + count: 1, // 默认9 | ||
| 80 | + sourceType: ['camera', 'album'], | ||
| 81 | + success: function (res) { | ||
| 82 | + var tempFilePaths = res.tempFiles; | ||
| 83 | + if (files.length + tempFilePaths.length > that.data.tpNum) { | ||
| 84 | + wx.showToast({ | ||
| 85 | + icon: 'none', | ||
| 86 | + title: "最多可上传" + that.data.tpNum + "张" | ||
| 87 | + }) | ||
| 88 | + return | ||
| 89 | + } | ||
| 90 | + let arr = [] | ||
| 91 | + for (var i = 0; i < tempFilePaths.length; i++) { | ||
| 92 | + arr.push(tempFilePaths[i].tempFilePath); | ||
| 93 | + } | ||
| 94 | + that.addFun('videoNew', arr, 'video', tempFilePaths) | ||
| 95 | + } | ||
| 96 | + }) | ||
| 97 | + }, | ||
| 98 | + // 上传文件或者视频 | ||
| 99 | + // path:上传到七牛的路径名称 | ||
| 100 | + // arr:要上传的文件 | ||
| 101 | + // type:video或者image | ||
| 102 | + // tempFilePaths:上传成功才能给页面加上传的图片或者视频 | ||
| 103 | + addFun(path, arr, type, tempFilePaths) { | ||
| 104 | + var that = this; | ||
| 105 | + var files = that.data.files; | ||
| 106 | + var filesHttps = that.data.filesHttps; | ||
| 107 | + let uploadPromises = arr.map(i => { | ||
| 108 | + return util.uploadFile(i, this.data.token, path).then(res => { | ||
| 109 | + return res; | ||
| 110 | + }); | ||
| 111 | + }); | ||
| 112 | + Promise.all(uploadPromises).then(results => { | ||
| 113 | + results.forEach(i => { | ||
| 114 | + filesHttps.push({ | ||
| 115 | + url: i, | ||
| 116 | + avinfo: type == 'video' ? true : false | ||
| 117 | + }) | ||
| 118 | + }) | ||
| 119 | + for (var i = 0; i < tempFilePaths.length; i++) { | ||
| 120 | + files.push({ | ||
| 121 | + path: tempFilePaths[i].tempFilePath, | ||
| 122 | + type | ||
| 123 | + }); | ||
| 124 | + } | ||
| 125 | + that.triggerEvent('tpupload', { | ||
| 126 | + files, | ||
| 127 | + filesHttps | ||
| 128 | + }) | ||
| 129 | + that.setData({ | ||
| 130 | + filesHttps, | ||
| 131 | + files | ||
| 132 | + }); | ||
| 133 | + }); | ||
| 134 | + }, | ||
| 135 | + // 选择图片 上传图片 | ||
| 136 | + uploadImages() { | ||
| 137 | + var that = this; | ||
| 138 | + var files = that.data.files; | ||
| 139 | + wx.chooseMedia({ | ||
| 140 | + mediaType: ['image'], | ||
| 141 | + count: this.data.tpNum, // 默认9 | ||
| 142 | + sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 | ||
| 143 | + sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 | ||
| 144 | + success: function (res) { | ||
| 145 | + var tempFilePaths = res.tempFiles; | ||
| 146 | + if (files.length + tempFilePaths.length > that.data.tpNum) { | ||
| 147 | + wx.showToast({ | ||
| 148 | + icon: 'none', | ||
| 149 | + title: "最多可上传" + that.data.tpNum + "张" | ||
| 150 | + }) | ||
| 151 | + return | ||
| 152 | + } | ||
| 153 | + let arr = [] | ||
| 154 | + for (var i = 0; i < tempFilePaths.length; i++) { | ||
| 155 | + arr.push(tempFilePaths[i].tempFilePath); | ||
| 156 | + } | ||
| 157 | + that.addFun('imagesNew', arr, 'image', tempFilePaths) | ||
| 158 | + } | ||
| 159 | + }); | ||
| 160 | + }, | ||
| 161 | + } | ||
| 162 | +}) |
| 1 | +<!--components/tpupload/tpupload.wxml--> | ||
| 2 | +<scroll-view class="uploader__bd" scroll-x="{{true}}" style="flex-wrap: nowrap; display: flex;height: 180rpx;width: auto;white-space: nowrap;"> | ||
| 3 | + <view class="uploade"> | ||
| 4 | + <view class="weui_uploader__file" wx:for="{{files}}"> | ||
| 5 | + <image wx:if="{{item.type=='image'}}" class="weui_uploader__img" src="{{item.path}}" bindtap="previewImg" mode="aspectFill" data-index="{{index}}"> | ||
| 6 | + </image> | ||
| 7 | + <video wx:if="{{item.type=='video'}}" class="weui_uploader__img" src="{{item.path}}" controls picture-in-picture-mode="{{['push', 'pop']}}" /> | ||
| 8 | + <image class="delete-btn" src="http://nosqn.colorcun.com/pinglun/p%20%286%29.png" data-index="{{index}}" catchtap="deleteFun"></image> | ||
| 9 | + </view> | ||
| 10 | + <view class="uploader__input"> | ||
| 11 | + <view class="uploader__input addimage" bindtap="uploadImages" wx:if="{{files.length < tpNum}}"> | ||
| 12 | + <image src="http://nosqn.colorcun.com/pinglun/p%20%2817%29.png" mode="aspectFit"></image> | ||
| 13 | + <view class="texts">上传图片</view> | ||
| 14 | + </view> | ||
| 15 | + </view> | ||
| 16 | + <view class="uploader__input"> | ||
| 17 | + <view class="uploader__input addimage" bindtap="uploadVideos" wx:if="{{files.length*1 < tpNum}}"> | ||
| 18 | + <image src="http://nosqn.colorcun.com/pinglun/p%20%2818%29.png" mode="aspectFit"></image> | ||
| 19 | + <view class="texts">上传视频</view> | ||
| 20 | + </view> | ||
| 21 | + </view> | ||
| 22 | + </view> | ||
| 23 | +</scroll-view> |
| 1 | +/* components/tpupload/tpupload.wxss */ | ||
| 2 | +.uploader__bd { | ||
| 3 | + padding: 0 20rpx; | ||
| 4 | +} | ||
| 5 | + | ||
| 6 | +.uploader__input { | ||
| 7 | + margin-right: 10rpx; | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +.uploade { | ||
| 11 | + flex-wrap: nowrap; | ||
| 12 | + display: flex; | ||
| 13 | + overflow-x: scroll; | ||
| 14 | + width: fit-content; | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +.addimage { | ||
| 18 | + width: 180rpx; | ||
| 19 | + height: 180rpx; | ||
| 20 | + border-radius: 16rpx; | ||
| 21 | + background: #F1F1F1; | ||
| 22 | + display: flex; | ||
| 23 | + flex-direction: column; | ||
| 24 | + align-items: center; | ||
| 25 | + justify-content: center; | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +.addimage image { | ||
| 29 | + width: 78rpx; | ||
| 30 | + height: 78rpx; | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +.delete-btn { | ||
| 34 | + position: absolute !important; | ||
| 35 | + top: 0; | ||
| 36 | + right: 0; | ||
| 37 | + width: 60rpx; | ||
| 38 | + height: 60rpx; | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +.weui_uploader__file { | ||
| 42 | + width: 180rpx; | ||
| 43 | + height: 180rpx; | ||
| 44 | + border-radius: 16rpx; | ||
| 45 | + position: relative; | ||
| 46 | + margin-right: 10rpx; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +.weui_uploader__img { | ||
| 50 | + width: 100%; | ||
| 51 | + height: 100%; | ||
| 52 | + border-radius: 16rpx; | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +.texts { | ||
| 56 | + font-size: 24rpx; | ||
| 57 | + font-weight: 400; | ||
| 58 | +} |
| @@ -49,7 +49,8 @@ Page({ | @@ -49,7 +49,8 @@ Page({ | ||
| 49 | }, | 49 | }, |
| 50 | files:[], //组件数据放入这里展示到页面上 | 50 | files:[], //组件数据放入这里展示到页面上 |
| 51 | hasAddFile:true,//出现上传加号 | 51 | hasAddFile:true,//出现上传加号 |
| 52 | - isnoshow:1, //是否匿名 | 52 | + isnoshow:1, //是否匿名 |
| 53 | + filesHttps:[], | ||
| 53 | }, | 54 | }, |
| 54 | 55 | ||
| 55 | /** | 56 | /** |
| @@ -123,24 +124,11 @@ Page({ | @@ -123,24 +124,11 @@ Page({ | ||
| 123 | //console.log('statEvent',e.detail.value) | 124 | //console.log('statEvent',e.detail.value) |
| 124 | this.statVal=e.detail.value | 125 | this.statVal=e.detail.value |
| 125 | }, | 126 | }, |
| 126 | - | ||
| 127 | - qnevent(e){ | ||
| 128 | - console.log('qnevent',e.detail); | ||
| 129 | - let files=e.detail.data | ||
| 130 | - if(e.detail.act=='uploadFail'){ | ||
| 131 | - files[e.detail.fileCurrent].progress=Math.random().toFixed(2) | ||
| 132 | - } | ||
| 133 | - files.forEach(f=>{ | ||
| 134 | - if(f.progress==100){ | ||
| 135 | - if(!f.remote || !f.remote.url){ | ||
| 136 | - f.progress=(90+Math.random()*9).toFixed(2) | ||
| 137 | - } | ||
| 138 | - } | ||
| 139 | - }) | 127 | + // 获取上传的图片或者视频 |
| 128 | + tpupload(e){ | ||
| 140 | this.setData({ | 129 | this.setData({ |
| 141 | - files:files, | ||
| 142 | - hasAddFile:files.length<this.data.upConf.count, | ||
| 143 | - scrollIntoView:'scrollIntoView', | 130 | + filesHttps:e.detail.filesHttps, |
| 131 | + files:e.detail.files, | ||
| 144 | }) | 132 | }) |
| 145 | }, | 133 | }, |
| 146 | displayImage(e){ | 134 | displayImage(e){ |
| @@ -153,16 +141,6 @@ Page({ | @@ -153,16 +141,6 @@ Page({ | ||
| 153 | urls:[path], | 141 | urls:[path], |
| 154 | }) | 142 | }) |
| 155 | }, | 143 | }, |
| 156 | - deleteImage(e){ | ||
| 157 | - let index=util.attr(e,'index') | ||
| 158 | - let files=this.data.files | ||
| 159 | - files.splice(index,1) | ||
| 160 | - this.setData({ | ||
| 161 | - files:files, | ||
| 162 | - hasAddFile:files.length<6 | ||
| 163 | - }) | ||
| 164 | - util.toast('图片已删除','none') | ||
| 165 | - }, | ||
| 166 | labelTap(e){ | 144 | labelTap(e){ |
| 167 | let labels=this.data.labels | 145 | let labels=this.data.labels |
| 168 | labels[util.attr(e,'index')].active=!labels[util.attr(e,'index')].active | 146 | labels[util.attr(e,'index')].active=!labels[util.attr(e,'index')].active |
| @@ -174,9 +152,7 @@ Page({ | @@ -174,9 +152,7 @@ Page({ | ||
| 174 | textareaInput(e){ | 152 | textareaInput(e){ |
| 175 | this.text=util.val(e).trim(); | 153 | this.text=util.val(e).trim(); |
| 176 | }, | 154 | }, |
| 177 | - submitIng:false, | ||
| 178 | submit(){ | 155 | submit(){ |
| 179 | - if(this.submitIng) return; | ||
| 180 | let eval_label=[] | 156 | let eval_label=[] |
| 181 | this.data.labels.some(l=>{ | 157 | this.data.labels.some(l=>{ |
| 182 | if(l.active){ | 158 | if(l.active){ |
| @@ -184,22 +160,12 @@ Page({ | @@ -184,22 +160,12 @@ Page({ | ||
| 184 | } | 160 | } |
| 185 | }) | 161 | }) |
| 186 | if(eval_label.length<1) return util.toast('请选择标签','none') | 162 | if(eval_label.length<1) return util.toast('请选择标签','none') |
| 187 | - let enclosure=[]; | ||
| 188 | - this.data.files.some(attr=>{ | ||
| 189 | - if(attr.remote){ | ||
| 190 | - enclosure.push(attr.remote) | ||
| 191 | - }else{ | ||
| 192 | - util.toast('请等待上传完成','none') | ||
| 193 | - throw new Error('请等待上传完成') | ||
| 194 | - } | ||
| 195 | - }) | ||
| 196 | - this.submitIng=true | ||
| 197 | let params={ | 163 | let params={ |
| 198 | sid:this.options.sid, | 164 | sid:this.options.sid, |
| 199 | rid:this.options.oid, | 165 | rid:this.options.oid, |
| 200 | eval_label:eval_label.toString(), | 166 | eval_label:eval_label.toString(), |
| 201 | author_openid:getApp().openid, | 167 | author_openid:getApp().openid, |
| 202 | - enclosure:JSON.stringify(enclosure), | 168 | + enclosure:JSON.stringify(this.data.filesHttps), |
| 203 | identity:1, | 169 | identity:1, |
| 204 | text:this.text||'', | 170 | text:this.text||'', |
| 205 | types:this.data.types,//types为1时 rid就是预订ID types为2时 rid就是套餐ID types为3时 rid就是卡券ID | 171 | types:this.data.types,//types为1时 rid就是预订ID types为2时 rid就是套餐ID types为3时 rid就是卡券ID |
| @@ -219,7 +185,7 @@ Page({ | @@ -219,7 +185,7 @@ Page({ | ||
| 219 | }) | 185 | }) |
| 220 | } | 186 | } |
| 221 | }).catch(e=>{ | 187 | }).catch(e=>{ |
| 222 | - this.submitIng=false | 188 | + console.log('catch',e); |
| 223 | }) | 189 | }) |
| 224 | }, | 190 | }, |
| 225 | // 设置券订单评论状态 | 191 | // 设置券订单评论状态 |
| @@ -4,6 +4,6 @@ | @@ -4,6 +4,6 @@ | ||
| 4 | "usingComponents": { | 4 | "usingComponents": { |
| 5 | "nav":"/components/nav/nav", | 5 | "nav":"/components/nav/nav", |
| 6 | "stat": "/components/2.0/pinglun/stat", | 6 | "stat": "/components/2.0/pinglun/stat", |
| 7 | - "qnupload": "plugin://vktool/qnupload" | 7 | + "tpupload": "/components/tpupload/tpupload" |
| 8 | } | 8 | } |
| 9 | } | 9 | } |
| @@ -25,47 +25,8 @@ | @@ -25,47 +25,8 @@ | ||
| 25 | bindinput="textareaInput" | 25 | bindinput="textareaInput" |
| 26 | placeholder="从包间环境、菜品口味、服务来评价餐厅,可以帮助更多想要订这家餐厅的人哦~" placeholder-style="color:#999999;font-size:30rpx;"></textarea> | 26 | placeholder="从包间环境、菜品口味、服务来评价餐厅,可以帮助更多想要订这家餐厅的人哦~" placeholder-style="color:#999999;font-size:30rpx;"></textarea> |
| 27 | </view> | 27 | </view> |
| 28 | - <scroll-view class="view" | ||
| 29 | - scroll-into-view="{{scrollIntoView}}" | ||
| 30 | - scroll-x="true" style="height: 100%;width: 100%;white-space: nowrap;"> | ||
| 31 | - <block wx:for="{{files}}" wx:key="fileskey"> | ||
| 32 | - <qnupload qnConf="{{qnConf}}" upConf="{{upConf}}" | ||
| 33 | - file="{{item}}" files="{{files}}" | ||
| 34 | - bindevent="qnevent" class="view qnupload"> | ||
| 35 | - <view class="view scroll-block flex flex-direction justify-center align-center" | ||
| 36 | - catchtap="displayImage" data-path="{{item.path}}" data-duration="{{item.duration}}"> | ||
| 37 | - <image class="view image" src="{{item.thumbTempFilePath||item.path}}"></image> | ||
| 38 | - <view class="view image-delete" catchtap="deleteImage" data-index="{{index}}"></view> | ||
| 39 | - <image class="view image-up" src=""></image> | ||
| 40 | - <view class="view image-text"></view> | ||
| 41 | - <view class="bg-image-video view" wx:if="{{item.duration>0}}"></view> | ||
| 42 | - </view> | ||
| 43 | - </qnupload> | ||
| 44 | - </block> | ||
| 45 | - <block wx:if="{{hasAddFile}}"> | ||
| 46 | - <qnupload | ||
| 47 | - qnConf="{{qnConf}}" upConf="{{upConf}}" | ||
| 48 | - file="{{item}}" files="{{files}}" | ||
| 49 | - bindevent="qnevent" class="view qnupload"> | ||
| 50 | - <view class="view scroll-block flex flex-direction justify-center align-center"> | ||
| 51 | - <image class="view image-up" src="http://nosqn.colorcun.com/pinglun/p%20%2817%29.png"></image> | ||
| 52 | - <view class="view image-text">上传图片</view> | ||
| 53 | - </view> | ||
| 54 | - </qnupload> | ||
| 55 | - <qnupload | ||
| 56 | - qnConf="{{qnConfVideo}}" upConf="{{upConfVideo}}" | ||
| 57 | - file="{{item}}" files="{{files}}" | ||
| 58 | - bindevent="qnevent" class="view qnupload"> | ||
| 59 | - <view class="view scroll-block flex flex-direction justify-center align-center"> | ||
| 60 | - <image class="view image" src="{{item.path}}"></image> | ||
| 61 | - <image class="view image-up" src="http://nosqn.colorcun.com/pinglun/p%20%2818%29.png"></image> | ||
| 62 | - <view class="view image-text">上传视频</view> | ||
| 63 | - </view> | ||
| 64 | - </qnupload> | ||
| 65 | - </block> | ||
| 66 | - | ||
| 67 | - <view id="scrollIntoView" class="qnupload" style="width: 0;"></view> | ||
| 68 | - </scroll-view> | 28 | + <tpupload bind:tpupload="tpupload" tpNum='6' ></tpupload> |
| 29 | + <view id="scrollIntoView" class="qnupload" style="width: 0;"></view> | ||
| 69 | <view class="flex-ll reamrk-noshow"> | 30 | <view class="flex-ll reamrk-noshow"> |
| 70 | <view class="remark-ratio flex-cc {{isnoshow==1 ? 'active' : 'border'}}" bindtap="setnoshow"> | 31 | <view class="remark-ratio flex-cc {{isnoshow==1 ? 'active' : 'border'}}" bindtap="setnoshow"> |
| 71 | <image src="http://nosqn.colorcun.com/right.jpg" wx:if="isnoshow==1"></image> | 32 | <image src="http://nosqn.colorcun.com/right.jpg" wx:if="isnoshow==1"></image> |
| @@ -115,4 +115,12 @@ | @@ -115,4 +115,12 @@ | ||
| 115 | .reamrk-noshow{ | 115 | .reamrk-noshow{ |
| 116 | padding: 44rpx 40rpx 0; | 116 | padding: 44rpx 40rpx 0; |
| 117 | box-sizing: border-box; | 117 | box-sizing: border-box; |
| 118 | +} | ||
| 119 | +.uploadimg{ | ||
| 120 | + width: 100rpx; | ||
| 121 | + height: 100rpx; | ||
| 122 | +} | ||
| 123 | +.deleteIcon{ | ||
| 124 | + width: 60rpx; | ||
| 125 | + height: 60rpx; | ||
| 118 | } | 126 | } |
| @@ -715,4 +715,10 @@ export default { | @@ -715,4 +715,10 @@ export default { | ||
| 715 | 'App.PlanCook.GetPlanCookByRid':{ | 715 | 'App.PlanCook.GetPlanCookByRid':{ |
| 716 | openid:'openid' | 716 | openid:'openid' |
| 717 | }, | 717 | }, |
| 718 | + | ||
| 719 | + // 获取七牛上传token信息 | ||
| 720 | + 'App.Qiniu.GetUploadToken':{ | ||
| 721 | + openid:'openid' | ||
| 722 | + }, | ||
| 723 | + | ||
| 718 | } | 724 | } |
miniprogram/utils/base64-js.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +exports.byteLength = byteLength | ||
| 4 | +exports.toByteArray = toByteArray | ||
| 5 | +exports.fromByteArray = fromByteArray | ||
| 6 | + | ||
| 7 | +var lookup = [] | ||
| 8 | +var revLookup = [] | ||
| 9 | +var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array | ||
| 10 | + | ||
| 11 | +var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' | ||
| 12 | +for (var i = 0, len = code.length; i < len; ++i) { | ||
| 13 | + lookup[i] = code[i] | ||
| 14 | + revLookup[code.charCodeAt(i)] = i | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +// Support decoding URL-safe base64 strings, as Node.js does. | ||
| 18 | +// See: https://en.wikipedia.org/wiki/Base64#URL_applications | ||
| 19 | +revLookup['-'.charCodeAt(0)] = 62 | ||
| 20 | +revLookup['_'.charCodeAt(0)] = 63 | ||
| 21 | + | ||
| 22 | +function getLens(b64) { | ||
| 23 | + var len = b64.length | ||
| 24 | + | ||
| 25 | + if (len % 4 > 0) { | ||
| 26 | + throw new Error('Invalid string. Length must be a multiple of 4') | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + // Trim off extra bytes after placeholder bytes are found | ||
| 30 | + // See: https://github.com/beatgammit/base64-js/issues/42 | ||
| 31 | + var validLen = b64.indexOf('=') | ||
| 32 | + if (validLen === -1) validLen = len | ||
| 33 | + | ||
| 34 | + var placeHoldersLen = validLen === len ? | ||
| 35 | + 0 : | ||
| 36 | + 4 - (validLen % 4) | ||
| 37 | + | ||
| 38 | + return [validLen, placeHoldersLen] | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +// base64 is 4/3 + up to two characters of the original data | ||
| 42 | +function byteLength(b64) { | ||
| 43 | + var lens = getLens(b64) | ||
| 44 | + var validLen = lens[0] | ||
| 45 | + var placeHoldersLen = lens[1] | ||
| 46 | + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +function _byteLength(b64, validLen, placeHoldersLen) { | ||
| 50 | + return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +function toByteArray(b64) { | ||
| 54 | + var tmp | ||
| 55 | + var lens = getLens(b64) | ||
| 56 | + var validLen = lens[0] | ||
| 57 | + var placeHoldersLen = lens[1] | ||
| 58 | + | ||
| 59 | + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) | ||
| 60 | + | ||
| 61 | + var curByte = 0 | ||
| 62 | + | ||
| 63 | + // if there are placeholders, only get up to the last complete 4 chars | ||
| 64 | + var len = placeHoldersLen > 0 ? | ||
| 65 | + validLen - 4 : | ||
| 66 | + validLen | ||
| 67 | + | ||
| 68 | + var i | ||
| 69 | + for (i = 0; i < len; i += 4) { | ||
| 70 | + tmp = | ||
| 71 | + (revLookup[b64.charCodeAt(i)] << 18) | | ||
| 72 | + (revLookup[b64.charCodeAt(i + 1)] << 12) | | ||
| 73 | + (revLookup[b64.charCodeAt(i + 2)] << 6) | | ||
| 74 | + revLookup[b64.charCodeAt(i + 3)] | ||
| 75 | + arr[curByte++] = (tmp >> 16) & 0xFF | ||
| 76 | + arr[curByte++] = (tmp >> 8) & 0xFF | ||
| 77 | + arr[curByte++] = tmp & 0xFF | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + if (placeHoldersLen === 2) { | ||
| 81 | + tmp = | ||
| 82 | + (revLookup[b64.charCodeAt(i)] << 2) | | ||
| 83 | + (revLookup[b64.charCodeAt(i + 1)] >> 4) | ||
| 84 | + arr[curByte++] = tmp & 0xFF | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + if (placeHoldersLen === 1) { | ||
| 88 | + tmp = | ||
| 89 | + (revLookup[b64.charCodeAt(i)] << 10) | | ||
| 90 | + (revLookup[b64.charCodeAt(i + 1)] << 4) | | ||
| 91 | + (revLookup[b64.charCodeAt(i + 2)] >> 2) | ||
| 92 | + arr[curByte++] = (tmp >> 8) & 0xFF | ||
| 93 | + arr[curByte++] = tmp & 0xFF | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + return arr | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +function tripletToBase64(num) { | ||
| 100 | + return lookup[num >> 18 & 0x3F] + | ||
| 101 | + lookup[num >> 12 & 0x3F] + | ||
| 102 | + lookup[num >> 6 & 0x3F] + | ||
| 103 | + lookup[num & 0x3F] | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +function encodeChunk(uint8, start, end) { | ||
| 107 | + var tmp | ||
| 108 | + var output = [] | ||
| 109 | + for (var i = start; i < end; i += 3) { | ||
| 110 | + tmp = | ||
| 111 | + ((uint8[i] << 16) & 0xFF0000) + | ||
| 112 | + ((uint8[i + 1] << 8) & 0xFF00) + | ||
| 113 | + (uint8[i + 2] & 0xFF) | ||
| 114 | + output.push(tripletToBase64(tmp)) | ||
| 115 | + } | ||
| 116 | + return output.join('') | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +function fromByteArray(uint8) { | ||
| 120 | + var tmp | ||
| 121 | + var len = uint8.length | ||
| 122 | + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes | ||
| 123 | + var parts = [] | ||
| 124 | + var maxChunkLength = 16383 // must be multiple of 3 | ||
| 125 | + | ||
| 126 | + // go through the array every three bytes, we'll deal with trailing stuff later | ||
| 127 | + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { | ||
| 128 | + parts.push(encodeChunk( | ||
| 129 | + uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) | ||
| 130 | + )) | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + // pad the end with zeros, but make sure to not forget the extra bytes | ||
| 134 | + if (extraBytes === 1) { | ||
| 135 | + tmp = uint8[len - 1] | ||
| 136 | + parts.push( | ||
| 137 | + lookup[tmp >> 2] + | ||
| 138 | + lookup[(tmp << 4) & 0x3F] + | ||
| 139 | + '==' | ||
| 140 | + ) | ||
| 141 | + } else if (extraBytes === 2) { | ||
| 142 | + tmp = (uint8[len - 2] << 8) + uint8[len - 1] | ||
| 143 | + parts.push( | ||
| 144 | + lookup[tmp >> 10] + | ||
| 145 | + lookup[(tmp >> 4) & 0x3F] + | ||
| 146 | + lookup[(tmp << 2) & 0x3F] + | ||
| 147 | + '=' | ||
| 148 | + ) | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + return parts.join('') | ||
| 152 | +} |
miniprogram/utils/buffer.js
0 → 100644
| 1 | +/*! | ||
| 2 | + * The buffer module from node.js, for the browser. | ||
| 3 | + * | ||
| 4 | + * @author Feross Aboukhadijeh <https://feross.org> | ||
| 5 | + * @license MIT | ||
| 6 | + */ | ||
| 7 | +/* eslint-disable no-proto */ | ||
| 8 | + | ||
| 9 | +'use strict' | ||
| 10 | + | ||
| 11 | +var base64 = require('base64-js') | ||
| 12 | +var ieee754 = require('ieee754') | ||
| 13 | +var customInspectSymbol = | ||
| 14 | + (typeof Symbol === 'function' && typeof Symbol.for === 'function') ? | ||
| 15 | + Symbol.for('nodejs.util.inspect.custom') : | ||
| 16 | + null | ||
| 17 | + | ||
| 18 | +exports.Buffer = Buffer | ||
| 19 | +exports.SlowBuffer = SlowBuffer | ||
| 20 | +exports.INSPECT_MAX_BYTES = 50 | ||
| 21 | + | ||
| 22 | +var K_MAX_LENGTH = 0x7fffffff | ||
| 23 | +exports.kMaxLength = K_MAX_LENGTH | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * If `Buffer.TYPED_ARRAY_SUPPORT`: | ||
| 27 | + * === true Use Uint8Array implementation (fastest) | ||
| 28 | + * === false Print warning and recommend using `buffer` v4.x which has an Object | ||
| 29 | + * implementation (most compatible, even IE6) | ||
| 30 | + * | ||
| 31 | + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | ||
| 32 | + * Opera 11.6+, iOS 4.2+. | ||
| 33 | + * | ||
| 34 | + * We report that the browser does not support typed arrays if the are not subclassable | ||
| 35 | + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` | ||
| 36 | + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support | ||
| 37 | + * for __proto__ and has a buggy typed array implementation. | ||
| 38 | + */ | ||
| 39 | +Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() | ||
| 40 | + | ||
| 41 | +if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && | ||
| 42 | + typeof console.error === 'function') { | ||
| 43 | + console.error( | ||
| 44 | + 'This browser lacks typed array (Uint8Array) support which is required by ' + | ||
| 45 | + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' | ||
| 46 | + ) | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +function typedArraySupport() { | ||
| 50 | + // Can typed array instances can be augmented? | ||
| 51 | + try { | ||
| 52 | + var arr = new Uint8Array(1) | ||
| 53 | + var proto = { | ||
| 54 | + foo: function () { | ||
| 55 | + return 42 | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + Object.setPrototypeOf(proto, Uint8Array.prototype) | ||
| 59 | + Object.setPrototypeOf(arr, proto) | ||
| 60 | + return arr.foo() === 42 | ||
| 61 | + } catch (e) { | ||
| 62 | + return false | ||
| 63 | + } | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +Object.defineProperty(Buffer.prototype, 'parent', { | ||
| 67 | + enumerable: true, | ||
| 68 | + get: function () { | ||
| 69 | + if (!Buffer.isBuffer(this)) return undefined | ||
| 70 | + return this.buffer | ||
| 71 | + } | ||
| 72 | +}) | ||
| 73 | + | ||
| 74 | +Object.defineProperty(Buffer.prototype, 'offset', { | ||
| 75 | + enumerable: true, | ||
| 76 | + get: function () { | ||
| 77 | + if (!Buffer.isBuffer(this)) return undefined | ||
| 78 | + return this.byteOffset | ||
| 79 | + } | ||
| 80 | +}) | ||
| 81 | + | ||
| 82 | +function createBuffer(length) { | ||
| 83 | + if (length > K_MAX_LENGTH) { | ||
| 84 | + throw new RangeError('The value "' + length + '" is invalid for option "size"') | ||
| 85 | + } | ||
| 86 | + // Return an augmented `Uint8Array` instance | ||
| 87 | + var buf = new Uint8Array(length) | ||
| 88 | + Object.setPrototypeOf(buf, Buffer.prototype) | ||
| 89 | + return buf | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +/** | ||
| 93 | + * The Buffer constructor returns instances of `Uint8Array` that have their | ||
| 94 | + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of | ||
| 95 | + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods | ||
| 96 | + * and the `Uint8Array` methods. Square bracket notation works as expected -- it | ||
| 97 | + * returns a single octet. | ||
| 98 | + * | ||
| 99 | + * The `Uint8Array` prototype remains unmodified. | ||
| 100 | + */ | ||
| 101 | + | ||
| 102 | +function Buffer(arg, encodingOrOffset, length) { | ||
| 103 | + // Common case. | ||
| 104 | + if (typeof arg === 'number') { | ||
| 105 | + if (typeof encodingOrOffset === 'string') { | ||
| 106 | + throw new TypeError( | ||
| 107 | + 'The "string" argument must be of type string. Received type number' | ||
| 108 | + ) | ||
| 109 | + } | ||
| 110 | + return allocUnsafe(arg) | ||
| 111 | + } | ||
| 112 | + return from(arg, encodingOrOffset, length) | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 | ||
| 116 | +if (typeof Symbol !== 'undefined' && Symbol.species != null && | ||
| 117 | + Buffer[Symbol.species] === Buffer) { | ||
| 118 | + Object.defineProperty(Buffer, Symbol.species, { | ||
| 119 | + value: null, | ||
| 120 | + configurable: true, | ||
| 121 | + enumerable: false, | ||
| 122 | + writable: false | ||
| 123 | + }) | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +Buffer.poolSize = 8192 // not used by this implementation | ||
| 127 | + | ||
| 128 | +function from(value, encodingOrOffset, length) { | ||
| 129 | + if (typeof value === 'string') { | ||
| 130 | + return fromString(value, encodingOrOffset) | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + if (ArrayBuffer.isView(value)) { | ||
| 134 | + return fromArrayLike(value) | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + if (value == null) { | ||
| 138 | + throw new TypeError( | ||
| 139 | + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + | ||
| 140 | + 'or Array-like Object. Received type ' + (typeof value) | ||
| 141 | + ) | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + if (isInstance(value, ArrayBuffer) || | ||
| 145 | + (value && isInstance(value.buffer, ArrayBuffer))) { | ||
| 146 | + return fromArrayBuffer(value, encodingOrOffset, length) | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + if (typeof value === 'number') { | ||
| 150 | + throw new TypeError( | ||
| 151 | + 'The "value" argument must not be of type number. Received type number' | ||
| 152 | + ) | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + var valueOf = value.valueOf && value.valueOf() | ||
| 156 | + if (valueOf != null && valueOf !== value) { | ||
| 157 | + return Buffer.from(valueOf, encodingOrOffset, length) | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + var b = fromObject(value) | ||
| 161 | + if (b) return b | ||
| 162 | + | ||
| 163 | + if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && | ||
| 164 | + typeof value[Symbol.toPrimitive] === 'function') { | ||
| 165 | + return Buffer.from( | ||
| 166 | + value[Symbol.toPrimitive]('string'), encodingOrOffset, length | ||
| 167 | + ) | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + throw new TypeError( | ||
| 171 | + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + | ||
| 172 | + 'or Array-like Object. Received type ' + (typeof value) | ||
| 173 | + ) | ||
| 174 | +} | ||
| 175 | + | ||
| 176 | +/** | ||
| 177 | + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError | ||
| 178 | + * if value is a number. | ||
| 179 | + * Buffer.from(str[, encoding]) | ||
| 180 | + * Buffer.from(array) | ||
| 181 | + * Buffer.from(buffer) | ||
| 182 | + * Buffer.from(arrayBuffer[, byteOffset[, length]]) | ||
| 183 | + **/ | ||
| 184 | +Buffer.from = function (value, encodingOrOffset, length) { | ||
| 185 | + return from(value, encodingOrOffset, length) | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: | ||
| 189 | +// https://github.com/feross/buffer/pull/148 | ||
| 190 | +Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype) | ||
| 191 | +Object.setPrototypeOf(Buffer, Uint8Array) | ||
| 192 | + | ||
| 193 | +function assertSize(size) { | ||
| 194 | + if (typeof size !== 'number') { | ||
| 195 | + throw new TypeError('"size" argument must be of type number') | ||
| 196 | + } else if (size < 0) { | ||
| 197 | + throw new RangeError('The value "' + size + '" is invalid for option "size"') | ||
| 198 | + } | ||
| 199 | +} | ||
| 200 | + | ||
| 201 | +function alloc(size, fill, encoding) { | ||
| 202 | + assertSize(size) | ||
| 203 | + if (size <= 0) { | ||
| 204 | + return createBuffer(size) | ||
| 205 | + } | ||
| 206 | + if (fill !== undefined) { | ||
| 207 | + // Only pay attention to encoding if it's a string. This | ||
| 208 | + // prevents accidentally sending in a number that would | ||
| 209 | + // be interpretted as a start offset. | ||
| 210 | + return typeof encoding === 'string' ? | ||
| 211 | + createBuffer(size).fill(fill, encoding) : | ||
| 212 | + createBuffer(size).fill(fill) | ||
| 213 | + } | ||
| 214 | + return createBuffer(size) | ||
| 215 | +} | ||
| 216 | + | ||
| 217 | +/** | ||
| 218 | + * Creates a new filled Buffer instance. | ||
| 219 | + * alloc(size[, fill[, encoding]]) | ||
| 220 | + **/ | ||
| 221 | +Buffer.alloc = function (size, fill, encoding) { | ||
| 222 | + return alloc(size, fill, encoding) | ||
| 223 | +} | ||
| 224 | + | ||
| 225 | +function allocUnsafe(size) { | ||
| 226 | + assertSize(size) | ||
| 227 | + return createBuffer(size < 0 ? 0 : checked(size) | 0) | ||
| 228 | +} | ||
| 229 | + | ||
| 230 | +/** | ||
| 231 | + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. | ||
| 232 | + * */ | ||
| 233 | +Buffer.allocUnsafe = function (size) { | ||
| 234 | + return allocUnsafe(size) | ||
| 235 | +} | ||
| 236 | +/** | ||
| 237 | + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | ||
| 238 | + */ | ||
| 239 | +Buffer.allocUnsafeSlow = function (size) { | ||
| 240 | + return allocUnsafe(size) | ||
| 241 | +} | ||
| 242 | + | ||
| 243 | +function fromString(string, encoding) { | ||
| 244 | + if (typeof encoding !== 'string' || encoding === '') { | ||
| 245 | + encoding = 'utf8' | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + if (!Buffer.isEncoding(encoding)) { | ||
| 249 | + throw new TypeError('Unknown encoding: ' + encoding) | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + var length = byteLength(string, encoding) | 0 | ||
| 253 | + var buf = createBuffer(length) | ||
| 254 | + | ||
| 255 | + var actual = buf.write(string, encoding) | ||
| 256 | + | ||
| 257 | + if (actual !== length) { | ||
| 258 | + // Writing a hex string, for example, that contains invalid characters will | ||
| 259 | + // cause everything after the first invalid character to be ignored. (e.g. | ||
| 260 | + // 'abxxcd' will be treated as 'ab') | ||
| 261 | + buf = buf.slice(0, actual) | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + return buf | ||
| 265 | +} | ||
| 266 | + | ||
| 267 | +function fromArrayLike(array) { | ||
| 268 | + var length = array.length < 0 ? 0 : checked(array.length) | 0 | ||
| 269 | + var buf = createBuffer(length) | ||
| 270 | + for (var i = 0; i < length; i += 1) { | ||
| 271 | + buf[i] = array[i] & 255 | ||
| 272 | + } | ||
| 273 | + return buf | ||
| 274 | +} | ||
| 275 | + | ||
| 276 | +function fromArrayBuffer(array, byteOffset, length) { | ||
| 277 | + if (byteOffset < 0 || array.byteLength < byteOffset) { | ||
| 278 | + throw new RangeError('"offset" is outside of buffer bounds') | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + if (array.byteLength < byteOffset + (length || 0)) { | ||
| 282 | + throw new RangeError('"length" is outside of buffer bounds') | ||
| 283 | + } | ||
| 284 | + | ||
| 285 | + var buf | ||
| 286 | + if (byteOffset === undefined && length === undefined) { | ||
| 287 | + buf = new Uint8Array(array) | ||
| 288 | + } else if (length === undefined) { | ||
| 289 | + buf = new Uint8Array(array, byteOffset) | ||
| 290 | + } else { | ||
| 291 | + buf = new Uint8Array(array, byteOffset, length) | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + // Return an augmented `Uint8Array` instance | ||
| 295 | + Object.setPrototypeOf(buf, Buffer.prototype) | ||
| 296 | + | ||
| 297 | + return buf | ||
| 298 | +} | ||
| 299 | + | ||
| 300 | +function fromObject(obj) { | ||
| 301 | + if (Buffer.isBuffer(obj)) { | ||
| 302 | + var len = checked(obj.length) | 0 | ||
| 303 | + var buf = createBuffer(len) | ||
| 304 | + | ||
| 305 | + if (buf.length === 0) { | ||
| 306 | + return buf | ||
| 307 | + } | ||
| 308 | + | ||
| 309 | + obj.copy(buf, 0, 0, len) | ||
| 310 | + return buf | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + if (obj.length !== undefined) { | ||
| 314 | + if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { | ||
| 315 | + return createBuffer(0) | ||
| 316 | + } | ||
| 317 | + return fromArrayLike(obj) | ||
| 318 | + } | ||
| 319 | + | ||
| 320 | + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { | ||
| 321 | + return fromArrayLike(obj.data) | ||
| 322 | + } | ||
| 323 | +} | ||
| 324 | + | ||
| 325 | +function checked(length) { | ||
| 326 | + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when | ||
| 327 | + // length is NaN (which is otherwise coerced to zero.) | ||
| 328 | + if (length >= K_MAX_LENGTH) { | ||
| 329 | + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | ||
| 330 | + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') | ||
| 331 | + } | ||
| 332 | + return length | 0 | ||
| 333 | +} | ||
| 334 | + | ||
| 335 | +function SlowBuffer(length) { | ||
| 336 | + if (+length != length) { // eslint-disable-line eqeqeq | ||
| 337 | + length = 0 | ||
| 338 | + } | ||
| 339 | + return Buffer.alloc(+length) | ||
| 340 | +} | ||
| 341 | + | ||
| 342 | +Buffer.isBuffer = function isBuffer(b) { | ||
| 343 | + return b != null && b._isBuffer === true && | ||
| 344 | + b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false | ||
| 345 | +} | ||
| 346 | + | ||
| 347 | +Buffer.compare = function compare(a, b) { | ||
| 348 | + if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) | ||
| 349 | + if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) | ||
| 350 | + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { | ||
| 351 | + throw new TypeError( | ||
| 352 | + 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' | ||
| 353 | + ) | ||
| 354 | + } | ||
| 355 | + | ||
| 356 | + if (a === b) return 0 | ||
| 357 | + | ||
| 358 | + var x = a.length | ||
| 359 | + var y = b.length | ||
| 360 | + | ||
| 361 | + for (var i = 0, len = Math.min(x, y); i < len; ++i) { | ||
| 362 | + if (a[i] !== b[i]) { | ||
| 363 | + x = a[i] | ||
| 364 | + y = b[i] | ||
| 365 | + break | ||
| 366 | + } | ||
| 367 | + } | ||
| 368 | + | ||
| 369 | + if (x < y) return -1 | ||
| 370 | + if (y < x) return 1 | ||
| 371 | + return 0 | ||
| 372 | +} | ||
| 373 | + | ||
| 374 | +Buffer.isEncoding = function isEncoding(encoding) { | ||
| 375 | + switch (String(encoding).toLowerCase()) { | ||
| 376 | + case 'hex': | ||
| 377 | + case 'utf8': | ||
| 378 | + case 'utf-8': | ||
| 379 | + case 'ascii': | ||
| 380 | + case 'latin1': | ||
| 381 | + case 'binary': | ||
| 382 | + case 'base64': | ||
| 383 | + case 'ucs2': | ||
| 384 | + case 'ucs-2': | ||
| 385 | + case 'utf16le': | ||
| 386 | + case 'utf-16le': | ||
| 387 | + return true | ||
| 388 | + default: | ||
| 389 | + return false | ||
| 390 | + } | ||
| 391 | +} | ||
| 392 | + | ||
| 393 | +Buffer.concat = function concat(list, length) { | ||
| 394 | + if (!Array.isArray(list)) { | ||
| 395 | + throw new TypeError('"list" argument must be an Array of Buffers') | ||
| 396 | + } | ||
| 397 | + | ||
| 398 | + if (list.length === 0) { | ||
| 399 | + return Buffer.alloc(0) | ||
| 400 | + } | ||
| 401 | + | ||
| 402 | + var i | ||
| 403 | + if (length === undefined) { | ||
| 404 | + length = 0 | ||
| 405 | + for (i = 0; i < list.length; ++i) { | ||
| 406 | + length += list[i].length | ||
| 407 | + } | ||
| 408 | + } | ||
| 409 | + | ||
| 410 | + var buffer = Buffer.allocUnsafe(length) | ||
| 411 | + var pos = 0 | ||
| 412 | + for (i = 0; i < list.length; ++i) { | ||
| 413 | + var buf = list[i] | ||
| 414 | + if (isInstance(buf, Uint8Array)) { | ||
| 415 | + buf = Buffer.from(buf) | ||
| 416 | + } | ||
| 417 | + if (!Buffer.isBuffer(buf)) { | ||
| 418 | + throw new TypeError('"list" argument must be an Array of Buffers') | ||
| 419 | + } | ||
| 420 | + buf.copy(buffer, pos) | ||
| 421 | + pos += buf.length | ||
| 422 | + } | ||
| 423 | + return buffer | ||
| 424 | +} | ||
| 425 | + | ||
| 426 | +function byteLength(string, encoding) { | ||
| 427 | + if (Buffer.isBuffer(string)) { | ||
| 428 | + return string.length | ||
| 429 | + } | ||
| 430 | + if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { | ||
| 431 | + return string.byteLength | ||
| 432 | + } | ||
| 433 | + if (typeof string !== 'string') { | ||
| 434 | + throw new TypeError( | ||
| 435 | + 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + | ||
| 436 | + 'Received type ' + typeof string | ||
| 437 | + ) | ||
| 438 | + } | ||
| 439 | + | ||
| 440 | + var len = string.length | ||
| 441 | + var mustMatch = (arguments.length > 2 && arguments[2] === true) | ||
| 442 | + if (!mustMatch && len === 0) return 0 | ||
| 443 | + | ||
| 444 | + // Use a for loop to avoid recursion | ||
| 445 | + var loweredCase = false | ||
| 446 | + for (;;) { | ||
| 447 | + switch (encoding) { | ||
| 448 | + case 'ascii': | ||
| 449 | + case 'latin1': | ||
| 450 | + case 'binary': | ||
| 451 | + return len | ||
| 452 | + case 'utf8': | ||
| 453 | + case 'utf-8': | ||
| 454 | + return utf8ToBytes(string).length | ||
| 455 | + case 'ucs2': | ||
| 456 | + case 'ucs-2': | ||
| 457 | + case 'utf16le': | ||
| 458 | + case 'utf-16le': | ||
| 459 | + return len * 2 | ||
| 460 | + case 'hex': | ||
| 461 | + return len >>> 1 | ||
| 462 | + case 'base64': | ||
| 463 | + return base64ToBytes(string).length | ||
| 464 | + default: | ||
| 465 | + if (loweredCase) { | ||
| 466 | + return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 | ||
| 467 | + } | ||
| 468 | + encoding = ('' + encoding).toLowerCase() | ||
| 469 | + loweredCase = true | ||
| 470 | + } | ||
| 471 | + } | ||
| 472 | +} | ||
| 473 | +Buffer.byteLength = byteLength | ||
| 474 | + | ||
| 475 | +function slowToString(encoding, start, end) { | ||
| 476 | + var loweredCase = false | ||
| 477 | + | ||
| 478 | + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only | ||
| 479 | + // property of a typed array. | ||
| 480 | + | ||
| 481 | + // This behaves neither like String nor Uint8Array in that we set start/end | ||
| 482 | + // to their upper/lower bounds if the value passed is out of range. | ||
| 483 | + // undefined is handled specially as per ECMA-262 6th Edition, | ||
| 484 | + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. | ||
| 485 | + if (start === undefined || start < 0) { | ||
| 486 | + start = 0 | ||
| 487 | + } | ||
| 488 | + // Return early if start > this.length. Done here to prevent potential uint32 | ||
| 489 | + // coercion fail below. | ||
| 490 | + if (start > this.length) { | ||
| 491 | + return '' | ||
| 492 | + } | ||
| 493 | + | ||
| 494 | + if (end === undefined || end > this.length) { | ||
| 495 | + end = this.length | ||
| 496 | + } | ||
| 497 | + | ||
| 498 | + if (end <= 0) { | ||
| 499 | + return '' | ||
| 500 | + } | ||
| 501 | + | ||
| 502 | + // Force coersion to uint32. This will also coerce falsey/NaN values to 0. | ||
| 503 | + end >>>= 0 | ||
| 504 | + start >>>= 0 | ||
| 505 | + | ||
| 506 | + if (end <= start) { | ||
| 507 | + return '' | ||
| 508 | + } | ||
| 509 | + | ||
| 510 | + if (!encoding) encoding = 'utf8' | ||
| 511 | + | ||
| 512 | + while (true) { | ||
| 513 | + switch (encoding) { | ||
| 514 | + case 'hex': | ||
| 515 | + return hexSlice(this, start, end) | ||
| 516 | + | ||
| 517 | + case 'utf8': | ||
| 518 | + case 'utf-8': | ||
| 519 | + return utf8Slice(this, start, end) | ||
| 520 | + | ||
| 521 | + case 'ascii': | ||
| 522 | + return asciiSlice(this, start, end) | ||
| 523 | + | ||
| 524 | + case 'latin1': | ||
| 525 | + case 'binary': | ||
| 526 | + return latin1Slice(this, start, end) | ||
| 527 | + | ||
| 528 | + case 'base64': | ||
| 529 | + return base64Slice(this, start, end) | ||
| 530 | + | ||
| 531 | + case 'ucs2': | ||
| 532 | + case 'ucs-2': | ||
| 533 | + case 'utf16le': | ||
| 534 | + case 'utf-16le': | ||
| 535 | + return utf16leSlice(this, start, end) | ||
| 536 | + | ||
| 537 | + default: | ||
| 538 | + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
| 539 | + encoding = (encoding + '').toLowerCase() | ||
| 540 | + loweredCase = true | ||
| 541 | + } | ||
| 542 | + } | ||
| 543 | +} | ||
| 544 | + | ||
| 545 | +// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) | ||
| 546 | +// to detect a Buffer instance. It's not possible to use `instanceof Buffer` | ||
| 547 | +// reliably in a browserify context because there could be multiple different | ||
| 548 | +// copies of the 'buffer' package in use. This method works even for Buffer | ||
| 549 | +// instances that were created from another copy of the `buffer` package. | ||
| 550 | +// See: https://github.com/feross/buffer/issues/154 | ||
| 551 | +Buffer.prototype._isBuffer = true | ||
| 552 | + | ||
| 553 | +function swap(b, n, m) { | ||
| 554 | + var i = b[n] | ||
| 555 | + b[n] = b[m] | ||
| 556 | + b[m] = i | ||
| 557 | +} | ||
| 558 | + | ||
| 559 | +Buffer.prototype.swap16 = function swap16() { | ||
| 560 | + var len = this.length | ||
| 561 | + if (len % 2 !== 0) { | ||
| 562 | + throw new RangeError('Buffer size must be a multiple of 16-bits') | ||
| 563 | + } | ||
| 564 | + for (var i = 0; i < len; i += 2) { | ||
| 565 | + swap(this, i, i + 1) | ||
| 566 | + } | ||
| 567 | + return this | ||
| 568 | +} | ||
| 569 | + | ||
| 570 | +Buffer.prototype.swap32 = function swap32() { | ||
| 571 | + var len = this.length | ||
| 572 | + if (len % 4 !== 0) { | ||
| 573 | + throw new RangeError('Buffer size must be a multiple of 32-bits') | ||
| 574 | + } | ||
| 575 | + for (var i = 0; i < len; i += 4) { | ||
| 576 | + swap(this, i, i + 3) | ||
| 577 | + swap(this, i + 1, i + 2) | ||
| 578 | + } | ||
| 579 | + return this | ||
| 580 | +} | ||
| 581 | + | ||
| 582 | +Buffer.prototype.swap64 = function swap64() { | ||
| 583 | + var len = this.length | ||
| 584 | + if (len % 8 !== 0) { | ||
| 585 | + throw new RangeError('Buffer size must be a multiple of 64-bits') | ||
| 586 | + } | ||
| 587 | + for (var i = 0; i < len; i += 8) { | ||
| 588 | + swap(this, i, i + 7) | ||
| 589 | + swap(this, i + 1, i + 6) | ||
| 590 | + swap(this, i + 2, i + 5) | ||
| 591 | + swap(this, i + 3, i + 4) | ||
| 592 | + } | ||
| 593 | + return this | ||
| 594 | +} | ||
| 595 | + | ||
| 596 | +Buffer.prototype.toString = function toString() { | ||
| 597 | + var length = this.length | ||
| 598 | + if (length === 0) return '' | ||
| 599 | + if (arguments.length === 0) return utf8Slice(this, 0, length) | ||
| 600 | + return slowToString.apply(this, arguments) | ||
| 601 | +} | ||
| 602 | + | ||
| 603 | +Buffer.prototype.toLocaleString = Buffer.prototype.toString | ||
| 604 | + | ||
| 605 | +Buffer.prototype.equals = function equals(b) { | ||
| 606 | + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
| 607 | + if (this === b) return true | ||
| 608 | + return Buffer.compare(this, b) === 0 | ||
| 609 | +} | ||
| 610 | + | ||
| 611 | +Buffer.prototype.inspect = function inspect() { | ||
| 612 | + var str = '' | ||
| 613 | + var max = exports.INSPECT_MAX_BYTES | ||
| 614 | + str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() | ||
| 615 | + if (this.length > max) str += ' ... ' | ||
| 616 | + return '<Buffer ' + str + '>' | ||
| 617 | +} | ||
| 618 | +if (customInspectSymbol) { | ||
| 619 | + Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect | ||
| 620 | +} | ||
| 621 | + | ||
| 622 | +Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { | ||
| 623 | + if (isInstance(target, Uint8Array)) { | ||
| 624 | + target = Buffer.from(target, target.offset, target.byteLength) | ||
| 625 | + } | ||
| 626 | + if (!Buffer.isBuffer(target)) { | ||
| 627 | + throw new TypeError( | ||
| 628 | + 'The "target" argument must be one of type Buffer or Uint8Array. ' + | ||
| 629 | + 'Received type ' + (typeof target) | ||
| 630 | + ) | ||
| 631 | + } | ||
| 632 | + | ||
| 633 | + if (start === undefined) { | ||
| 634 | + start = 0 | ||
| 635 | + } | ||
| 636 | + if (end === undefined) { | ||
| 637 | + end = target ? target.length : 0 | ||
| 638 | + } | ||
| 639 | + if (thisStart === undefined) { | ||
| 640 | + thisStart = 0 | ||
| 641 | + } | ||
| 642 | + if (thisEnd === undefined) { | ||
| 643 | + thisEnd = this.length | ||
| 644 | + } | ||
| 645 | + | ||
| 646 | + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { | ||
| 647 | + throw new RangeError('out of range index') | ||
| 648 | + } | ||
| 649 | + | ||
| 650 | + if (thisStart >= thisEnd && start >= end) { | ||
| 651 | + return 0 | ||
| 652 | + } | ||
| 653 | + if (thisStart >= thisEnd) { | ||
| 654 | + return -1 | ||
| 655 | + } | ||
| 656 | + if (start >= end) { | ||
| 657 | + return 1 | ||
| 658 | + } | ||
| 659 | + | ||
| 660 | + start >>>= 0 | ||
| 661 | + end >>>= 0 | ||
| 662 | + thisStart >>>= 0 | ||
| 663 | + thisEnd >>>= 0 | ||
| 664 | + | ||
| 665 | + if (this === target) return 0 | ||
| 666 | + | ||
| 667 | + var x = thisEnd - thisStart | ||
| 668 | + var y = end - start | ||
| 669 | + var len = Math.min(x, y) | ||
| 670 | + | ||
| 671 | + var thisCopy = this.slice(thisStart, thisEnd) | ||
| 672 | + var targetCopy = target.slice(start, end) | ||
| 673 | + | ||
| 674 | + for (var i = 0; i < len; ++i) { | ||
| 675 | + if (thisCopy[i] !== targetCopy[i]) { | ||
| 676 | + x = thisCopy[i] | ||
| 677 | + y = targetCopy[i] | ||
| 678 | + break | ||
| 679 | + } | ||
| 680 | + } | ||
| 681 | + | ||
| 682 | + if (x < y) return -1 | ||
| 683 | + if (y < x) return 1 | ||
| 684 | + return 0 | ||
| 685 | +} | ||
| 686 | + | ||
| 687 | +// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, | ||
| 688 | +// OR the last index of `val` in `buffer` at offset <= `byteOffset`. | ||
| 689 | +// | ||
| 690 | +// Arguments: | ||
| 691 | +// - buffer - a Buffer to search | ||
| 692 | +// - val - a string, Buffer, or number | ||
| 693 | +// - byteOffset - an index into `buffer`; will be clamped to an int32 | ||
| 694 | +// - encoding - an optional encoding, relevant is val is a string | ||
| 695 | +// - dir - true for indexOf, false for lastIndexOf | ||
| 696 | +function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { | ||
| 697 | + // Empty buffer means no match | ||
| 698 | + if (buffer.length === 0) return -1 | ||
| 699 | + | ||
| 700 | + // Normalize byteOffset | ||
| 701 | + if (typeof byteOffset === 'string') { | ||
| 702 | + encoding = byteOffset | ||
| 703 | + byteOffset = 0 | ||
| 704 | + } else if (byteOffset > 0x7fffffff) { | ||
| 705 | + byteOffset = 0x7fffffff | ||
| 706 | + } else if (byteOffset < -0x80000000) { | ||
| 707 | + byteOffset = -0x80000000 | ||
| 708 | + } | ||
| 709 | + byteOffset = +byteOffset // Coerce to Number. | ||
| 710 | + if (numberIsNaN(byteOffset)) { | ||
| 711 | + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer | ||
| 712 | + byteOffset = dir ? 0 : (buffer.length - 1) | ||
| 713 | + } | ||
| 714 | + | ||
| 715 | + // Normalize byteOffset: negative offsets start from the end of the buffer | ||
| 716 | + if (byteOffset < 0) byteOffset = buffer.length + byteOffset | ||
| 717 | + if (byteOffset >= buffer.length) { | ||
| 718 | + if (dir) return -1 | ||
| 719 | + else byteOffset = buffer.length - 1 | ||
| 720 | + } else if (byteOffset < 0) { | ||
| 721 | + if (dir) byteOffset = 0 | ||
| 722 | + else return -1 | ||
| 723 | + } | ||
| 724 | + | ||
| 725 | + // Normalize val | ||
| 726 | + if (typeof val === 'string') { | ||
| 727 | + val = Buffer.from(val, encoding) | ||
| 728 | + } | ||
| 729 | + | ||
| 730 | + // Finally, search either indexOf (if dir is true) or lastIndexOf | ||
| 731 | + if (Buffer.isBuffer(val)) { | ||
| 732 | + // Special case: looking for empty string/buffer always fails | ||
| 733 | + if (val.length === 0) { | ||
| 734 | + return -1 | ||
| 735 | + } | ||
| 736 | + return arrayIndexOf(buffer, val, byteOffset, encoding, dir) | ||
| 737 | + } else if (typeof val === 'number') { | ||
| 738 | + val = val & 0xFF // Search for a byte value [0-255] | ||
| 739 | + if (typeof Uint8Array.prototype.indexOf === 'function') { | ||
| 740 | + if (dir) { | ||
| 741 | + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) | ||
| 742 | + } else { | ||
| 743 | + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) | ||
| 744 | + } | ||
| 745 | + } | ||
| 746 | + return arrayIndexOf(buffer, [val], byteOffset, encoding, dir) | ||
| 747 | + } | ||
| 748 | + | ||
| 749 | + throw new TypeError('val must be string, number or Buffer') | ||
| 750 | +} | ||
| 751 | + | ||
| 752 | +function arrayIndexOf(arr, val, byteOffset, encoding, dir) { | ||
| 753 | + var indexSize = 1 | ||
| 754 | + var arrLength = arr.length | ||
| 755 | + var valLength = val.length | ||
| 756 | + | ||
| 757 | + if (encoding !== undefined) { | ||
| 758 | + encoding = String(encoding).toLowerCase() | ||
| 759 | + if (encoding === 'ucs2' || encoding === 'ucs-2' || | ||
| 760 | + encoding === 'utf16le' || encoding === 'utf-16le') { | ||
| 761 | + if (arr.length < 2 || val.length < 2) { | ||
| 762 | + return -1 | ||
| 763 | + } | ||
| 764 | + indexSize = 2 | ||
| 765 | + arrLength /= 2 | ||
| 766 | + valLength /= 2 | ||
| 767 | + byteOffset /= 2 | ||
| 768 | + } | ||
| 769 | + } | ||
| 770 | + | ||
| 771 | + function read(buf, i) { | ||
| 772 | + if (indexSize === 1) { | ||
| 773 | + return buf[i] | ||
| 774 | + } else { | ||
| 775 | + return buf.readUInt16BE(i * indexSize) | ||
| 776 | + } | ||
| 777 | + } | ||
| 778 | + | ||
| 779 | + var i | ||
| 780 | + if (dir) { | ||
| 781 | + var foundIndex = -1 | ||
| 782 | + for (i = byteOffset; i < arrLength; i++) { | ||
| 783 | + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { | ||
| 784 | + if (foundIndex === -1) foundIndex = i | ||
| 785 | + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize | ||
| 786 | + } else { | ||
| 787 | + if (foundIndex !== -1) i -= i - foundIndex | ||
| 788 | + foundIndex = -1 | ||
| 789 | + } | ||
| 790 | + } | ||
| 791 | + } else { | ||
| 792 | + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength | ||
| 793 | + for (i = byteOffset; i >= 0; i--) { | ||
| 794 | + var found = true | ||
| 795 | + for (var j = 0; j < valLength; j++) { | ||
| 796 | + if (read(arr, i + j) !== read(val, j)) { | ||
| 797 | + found = false | ||
| 798 | + break | ||
| 799 | + } | ||
| 800 | + } | ||
| 801 | + if (found) return i | ||
| 802 | + } | ||
| 803 | + } | ||
| 804 | + | ||
| 805 | + return -1 | ||
| 806 | +} | ||
| 807 | + | ||
| 808 | +Buffer.prototype.includes = function includes(val, byteOffset, encoding) { | ||
| 809 | + return this.indexOf(val, byteOffset, encoding) !== -1 | ||
| 810 | +} | ||
| 811 | + | ||
| 812 | +Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { | ||
| 813 | + return bidirectionalIndexOf(this, val, byteOffset, encoding, true) | ||
| 814 | +} | ||
| 815 | + | ||
| 816 | +Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { | ||
| 817 | + return bidirectionalIndexOf(this, val, byteOffset, encoding, false) | ||
| 818 | +} | ||
| 819 | + | ||
| 820 | +function hexWrite(buf, string, offset, length) { | ||
| 821 | + offset = Number(offset) || 0 | ||
| 822 | + var remaining = buf.length - offset | ||
| 823 | + if (!length) { | ||
| 824 | + length = remaining | ||
| 825 | + } else { | ||
| 826 | + length = Number(length) | ||
| 827 | + if (length > remaining) { | ||
| 828 | + length = remaining | ||
| 829 | + } | ||
| 830 | + } | ||
| 831 | + | ||
| 832 | + var strLen = string.length | ||
| 833 | + | ||
| 834 | + if (length > strLen / 2) { | ||
| 835 | + length = strLen / 2 | ||
| 836 | + } | ||
| 837 | + for (var i = 0; i < length; ++i) { | ||
| 838 | + var parsed = parseInt(string.substr(i * 2, 2), 16) | ||
| 839 | + if (numberIsNaN(parsed)) return i | ||
| 840 | + buf[offset + i] = parsed | ||
| 841 | + } | ||
| 842 | + return i | ||
| 843 | +} | ||
| 844 | + | ||
| 845 | +function utf8Write(buf, string, offset, length) { | ||
| 846 | + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) | ||
| 847 | +} | ||
| 848 | + | ||
| 849 | +function asciiWrite(buf, string, offset, length) { | ||
| 850 | + return blitBuffer(asciiToBytes(string), buf, offset, length) | ||
| 851 | +} | ||
| 852 | + | ||
| 853 | +function latin1Write(buf, string, offset, length) { | ||
| 854 | + return asciiWrite(buf, string, offset, length) | ||
| 855 | +} | ||
| 856 | + | ||
| 857 | +function base64Write(buf, string, offset, length) { | ||
| 858 | + return blitBuffer(base64ToBytes(string), buf, offset, length) | ||
| 859 | +} | ||
| 860 | + | ||
| 861 | +function ucs2Write(buf, string, offset, length) { | ||
| 862 | + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) | ||
| 863 | +} | ||
| 864 | + | ||
| 865 | +Buffer.prototype.write = function write(string, offset, length, encoding) { | ||
| 866 | + // Buffer#write(string) | ||
| 867 | + if (offset === undefined) { | ||
| 868 | + encoding = 'utf8' | ||
| 869 | + length = this.length | ||
| 870 | + offset = 0 | ||
| 871 | + // Buffer#write(string, encoding) | ||
| 872 | + } else if (length === undefined && typeof offset === 'string') { | ||
| 873 | + encoding = offset | ||
| 874 | + length = this.length | ||
| 875 | + offset = 0 | ||
| 876 | + // Buffer#write(string, offset[, length][, encoding]) | ||
| 877 | + } else if (isFinite(offset)) { | ||
| 878 | + offset = offset >>> 0 | ||
| 879 | + if (isFinite(length)) { | ||
| 880 | + length = length >>> 0 | ||
| 881 | + if (encoding === undefined) encoding = 'utf8' | ||
| 882 | + } else { | ||
| 883 | + encoding = length | ||
| 884 | + length = undefined | ||
| 885 | + } | ||
| 886 | + } else { | ||
| 887 | + throw new Error( | ||
| 888 | + 'Buffer.write(string, encoding, offset[, length]) is no longer supported' | ||
| 889 | + ) | ||
| 890 | + } | ||
| 891 | + | ||
| 892 | + var remaining = this.length - offset | ||
| 893 | + if (length === undefined || length > remaining) length = remaining | ||
| 894 | + | ||
| 895 | + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { | ||
| 896 | + throw new RangeError('Attempt to write outside buffer bounds') | ||
| 897 | + } | ||
| 898 | + | ||
| 899 | + if (!encoding) encoding = 'utf8' | ||
| 900 | + | ||
| 901 | + var loweredCase = false | ||
| 902 | + for (;;) { | ||
| 903 | + switch (encoding) { | ||
| 904 | + case 'hex': | ||
| 905 | + return hexWrite(this, string, offset, length) | ||
| 906 | + | ||
| 907 | + case 'utf8': | ||
| 908 | + case 'utf-8': | ||
| 909 | + return utf8Write(this, string, offset, length) | ||
| 910 | + | ||
| 911 | + case 'ascii': | ||
| 912 | + return asciiWrite(this, string, offset, length) | ||
| 913 | + | ||
| 914 | + case 'latin1': | ||
| 915 | + case 'binary': | ||
| 916 | + return latin1Write(this, string, offset, length) | ||
| 917 | + | ||
| 918 | + case 'base64': | ||
| 919 | + // Warning: maxLength not taken into account in base64Write | ||
| 920 | + return base64Write(this, string, offset, length) | ||
| 921 | + | ||
| 922 | + case 'ucs2': | ||
| 923 | + case 'ucs-2': | ||
| 924 | + case 'utf16le': | ||
| 925 | + case 'utf-16le': | ||
| 926 | + return ucs2Write(this, string, offset, length) | ||
| 927 | + | ||
| 928 | + default: | ||
| 929 | + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
| 930 | + encoding = ('' + encoding).toLowerCase() | ||
| 931 | + loweredCase = true | ||
| 932 | + } | ||
| 933 | + } | ||
| 934 | +} | ||
| 935 | + | ||
| 936 | +Buffer.prototype.toJSON = function toJSON() { | ||
| 937 | + return { | ||
| 938 | + type: 'Buffer', | ||
| 939 | + data: Array.prototype.slice.call(this._arr || this, 0) | ||
| 940 | + } | ||
| 941 | +} | ||
| 942 | + | ||
| 943 | +function base64Slice(buf, start, end) { | ||
| 944 | + if (start === 0 && end === buf.length) { | ||
| 945 | + return base64.fromByteArray(buf) | ||
| 946 | + } else { | ||
| 947 | + return base64.fromByteArray(buf.slice(start, end)) | ||
| 948 | + } | ||
| 949 | +} | ||
| 950 | + | ||
| 951 | +function utf8Slice(buf, start, end) { | ||
| 952 | + end = Math.min(buf.length, end) | ||
| 953 | + var res = [] | ||
| 954 | + | ||
| 955 | + var i = start | ||
| 956 | + while (i < end) { | ||
| 957 | + var firstByte = buf[i] | ||
| 958 | + var codePoint = null | ||
| 959 | + var bytesPerSequence = (firstByte > 0xEF) ? 4 : | ||
| 960 | + (firstByte > 0xDF) ? 3 : | ||
| 961 | + (firstByte > 0xBF) ? 2 : | ||
| 962 | + 1 | ||
| 963 | + | ||
| 964 | + if (i + bytesPerSequence <= end) { | ||
| 965 | + var secondByte, thirdByte, fourthByte, tempCodePoint | ||
| 966 | + | ||
| 967 | + switch (bytesPerSequence) { | ||
| 968 | + case 1: | ||
| 969 | + if (firstByte < 0x80) { | ||
| 970 | + codePoint = firstByte | ||
| 971 | + } | ||
| 972 | + break | ||
| 973 | + case 2: | ||
| 974 | + secondByte = buf[i + 1] | ||
| 975 | + if ((secondByte & 0xC0) === 0x80) { | ||
| 976 | + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) | ||
| 977 | + if (tempCodePoint > 0x7F) { | ||
| 978 | + codePoint = tempCodePoint | ||
| 979 | + } | ||
| 980 | + } | ||
| 981 | + break | ||
| 982 | + case 3: | ||
| 983 | + secondByte = buf[i + 1] | ||
| 984 | + thirdByte = buf[i + 2] | ||
| 985 | + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { | ||
| 986 | + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) | ||
| 987 | + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { | ||
| 988 | + codePoint = tempCodePoint | ||
| 989 | + } | ||
| 990 | + } | ||
| 991 | + break | ||
| 992 | + case 4: | ||
| 993 | + secondByte = buf[i + 1] | ||
| 994 | + thirdByte = buf[i + 2] | ||
| 995 | + fourthByte = buf[i + 3] | ||
| 996 | + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { | ||
| 997 | + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) | ||
| 998 | + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { | ||
| 999 | + codePoint = tempCodePoint | ||
| 1000 | + } | ||
| 1001 | + } | ||
| 1002 | + } | ||
| 1003 | + } | ||
| 1004 | + | ||
| 1005 | + if (codePoint === null) { | ||
| 1006 | + // we did not generate a valid codePoint so insert a | ||
| 1007 | + // replacement char (U+FFFD) and advance only 1 byte | ||
| 1008 | + codePoint = 0xFFFD | ||
| 1009 | + bytesPerSequence = 1 | ||
| 1010 | + } else if (codePoint > 0xFFFF) { | ||
| 1011 | + // encode to utf16 (surrogate pair dance) | ||
| 1012 | + codePoint -= 0x10000 | ||
| 1013 | + res.push(codePoint >>> 10 & 0x3FF | 0xD800) | ||
| 1014 | + codePoint = 0xDC00 | codePoint & 0x3FF | ||
| 1015 | + } | ||
| 1016 | + | ||
| 1017 | + res.push(codePoint) | ||
| 1018 | + i += bytesPerSequence | ||
| 1019 | + } | ||
| 1020 | + | ||
| 1021 | + return decodeCodePointsArray(res) | ||
| 1022 | +} | ||
| 1023 | + | ||
| 1024 | +// Based on http://stackoverflow.com/a/22747272/680742, the browser with | ||
| 1025 | +// the lowest limit is Chrome, with 0x10000 args. | ||
| 1026 | +// We go 1 magnitude less, for safety | ||
| 1027 | +var MAX_ARGUMENTS_LENGTH = 0x1000 | ||
| 1028 | + | ||
| 1029 | +function decodeCodePointsArray(codePoints) { | ||
| 1030 | + var len = codePoints.length | ||
| 1031 | + if (len <= MAX_ARGUMENTS_LENGTH) { | ||
| 1032 | + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() | ||
| 1033 | + } | ||
| 1034 | + | ||
| 1035 | + // Decode in chunks to avoid "call stack size exceeded". | ||
| 1036 | + var res = '' | ||
| 1037 | + var i = 0 | ||
| 1038 | + while (i < len) { | ||
| 1039 | + res += String.fromCharCode.apply( | ||
| 1040 | + String, | ||
| 1041 | + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) | ||
| 1042 | + ) | ||
| 1043 | + } | ||
| 1044 | + return res | ||
| 1045 | +} | ||
| 1046 | + | ||
| 1047 | +function asciiSlice(buf, start, end) { | ||
| 1048 | + var ret = '' | ||
| 1049 | + end = Math.min(buf.length, end) | ||
| 1050 | + | ||
| 1051 | + for (var i = start; i < end; ++i) { | ||
| 1052 | + ret += String.fromCharCode(buf[i] & 0x7F) | ||
| 1053 | + } | ||
| 1054 | + return ret | ||
| 1055 | +} | ||
| 1056 | + | ||
| 1057 | +function latin1Slice(buf, start, end) { | ||
| 1058 | + var ret = '' | ||
| 1059 | + end = Math.min(buf.length, end) | ||
| 1060 | + | ||
| 1061 | + for (var i = start; i < end; ++i) { | ||
| 1062 | + ret += String.fromCharCode(buf[i]) | ||
| 1063 | + } | ||
| 1064 | + return ret | ||
| 1065 | +} | ||
| 1066 | + | ||
| 1067 | +function hexSlice(buf, start, end) { | ||
| 1068 | + var len = buf.length | ||
| 1069 | + | ||
| 1070 | + if (!start || start < 0) start = 0 | ||
| 1071 | + if (!end || end < 0 || end > len) end = len | ||
| 1072 | + | ||
| 1073 | + var out = '' | ||
| 1074 | + for (var i = start; i < end; ++i) { | ||
| 1075 | + out += hexSliceLookupTable[buf[i]] | ||
| 1076 | + } | ||
| 1077 | + return out | ||
| 1078 | +} | ||
| 1079 | + | ||
| 1080 | +function utf16leSlice(buf, start, end) { | ||
| 1081 | + var bytes = buf.slice(start, end) | ||
| 1082 | + var res = '' | ||
| 1083 | + for (var i = 0; i < bytes.length; i += 2) { | ||
| 1084 | + res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) | ||
| 1085 | + } | ||
| 1086 | + return res | ||
| 1087 | +} | ||
| 1088 | + | ||
| 1089 | +Buffer.prototype.slice = function slice(start, end) { | ||
| 1090 | + var len = this.length | ||
| 1091 | + start = ~~start | ||
| 1092 | + end = end === undefined ? len : ~~end | ||
| 1093 | + | ||
| 1094 | + if (start < 0) { | ||
| 1095 | + start += len | ||
| 1096 | + if (start < 0) start = 0 | ||
| 1097 | + } else if (start > len) { | ||
| 1098 | + start = len | ||
| 1099 | + } | ||
| 1100 | + | ||
| 1101 | + if (end < 0) { | ||
| 1102 | + end += len | ||
| 1103 | + if (end < 0) end = 0 | ||
| 1104 | + } else if (end > len) { | ||
| 1105 | + end = len | ||
| 1106 | + } | ||
| 1107 | + | ||
| 1108 | + if (end < start) end = start | ||
| 1109 | + | ||
| 1110 | + var newBuf = this.subarray(start, end) | ||
| 1111 | + // Return an augmented `Uint8Array` instance | ||
| 1112 | + Object.setPrototypeOf(newBuf, Buffer.prototype) | ||
| 1113 | + | ||
| 1114 | + return newBuf | ||
| 1115 | +} | ||
| 1116 | + | ||
| 1117 | +/* | ||
| 1118 | + * Need to make sure that buffer isn't trying to write out of bounds. | ||
| 1119 | + */ | ||
| 1120 | +function checkOffset(offset, ext, length) { | ||
| 1121 | + if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') | ||
| 1122 | + if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') | ||
| 1123 | +} | ||
| 1124 | + | ||
| 1125 | +Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { | ||
| 1126 | + offset = offset >>> 0 | ||
| 1127 | + byteLength = byteLength >>> 0 | ||
| 1128 | + if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
| 1129 | + | ||
| 1130 | + var val = this[offset] | ||
| 1131 | + var mul = 1 | ||
| 1132 | + var i = 0 | ||
| 1133 | + while (++i < byteLength && (mul *= 0x100)) { | ||
| 1134 | + val += this[offset + i] * mul | ||
| 1135 | + } | ||
| 1136 | + | ||
| 1137 | + return val | ||
| 1138 | +} | ||
| 1139 | + | ||
| 1140 | +Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { | ||
| 1141 | + offset = offset >>> 0 | ||
| 1142 | + byteLength = byteLength >>> 0 | ||
| 1143 | + if (!noAssert) { | ||
| 1144 | + checkOffset(offset, byteLength, this.length) | ||
| 1145 | + } | ||
| 1146 | + | ||
| 1147 | + var val = this[offset + --byteLength] | ||
| 1148 | + var mul = 1 | ||
| 1149 | + while (byteLength > 0 && (mul *= 0x100)) { | ||
| 1150 | + val += this[offset + --byteLength] * mul | ||
| 1151 | + } | ||
| 1152 | + | ||
| 1153 | + return val | ||
| 1154 | +} | ||
| 1155 | + | ||
| 1156 | +Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { | ||
| 1157 | + offset = offset >>> 0 | ||
| 1158 | + if (!noAssert) checkOffset(offset, 1, this.length) | ||
| 1159 | + return this[offset] | ||
| 1160 | +} | ||
| 1161 | + | ||
| 1162 | +Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { | ||
| 1163 | + offset = offset >>> 0 | ||
| 1164 | + if (!noAssert) checkOffset(offset, 2, this.length) | ||
| 1165 | + return this[offset] | (this[offset + 1] << 8) | ||
| 1166 | +} | ||
| 1167 | + | ||
| 1168 | +Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { | ||
| 1169 | + offset = offset >>> 0 | ||
| 1170 | + if (!noAssert) checkOffset(offset, 2, this.length) | ||
| 1171 | + return (this[offset] << 8) | this[offset + 1] | ||
| 1172 | +} | ||
| 1173 | + | ||
| 1174 | +Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { | ||
| 1175 | + offset = offset >>> 0 | ||
| 1176 | + if (!noAssert) checkOffset(offset, 4, this.length) | ||
| 1177 | + | ||
| 1178 | + return ((this[offset]) | | ||
| 1179 | + (this[offset + 1] << 8) | | ||
| 1180 | + (this[offset + 2] << 16)) + | ||
| 1181 | + (this[offset + 3] * 0x1000000) | ||
| 1182 | +} | ||
| 1183 | + | ||
| 1184 | +Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { | ||
| 1185 | + offset = offset >>> 0 | ||
| 1186 | + if (!noAssert) checkOffset(offset, 4, this.length) | ||
| 1187 | + | ||
| 1188 | + return (this[offset] * 0x1000000) + | ||
| 1189 | + ((this[offset + 1] << 16) | | ||
| 1190 | + (this[offset + 2] << 8) | | ||
| 1191 | + this[offset + 3]) | ||
| 1192 | +} | ||
| 1193 | + | ||
| 1194 | +Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { | ||
| 1195 | + offset = offset >>> 0 | ||
| 1196 | + byteLength = byteLength >>> 0 | ||
| 1197 | + if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
| 1198 | + | ||
| 1199 | + var val = this[offset] | ||
| 1200 | + var mul = 1 | ||
| 1201 | + var i = 0 | ||
| 1202 | + while (++i < byteLength && (mul *= 0x100)) { | ||
| 1203 | + val += this[offset + i] * mul | ||
| 1204 | + } | ||
| 1205 | + mul *= 0x80 | ||
| 1206 | + | ||
| 1207 | + if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
| 1208 | + | ||
| 1209 | + return val | ||
| 1210 | +} | ||
| 1211 | + | ||
| 1212 | +Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { | ||
| 1213 | + offset = offset >>> 0 | ||
| 1214 | + byteLength = byteLength >>> 0 | ||
| 1215 | + if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
| 1216 | + | ||
| 1217 | + var i = byteLength | ||
| 1218 | + var mul = 1 | ||
| 1219 | + var val = this[offset + --i] | ||
| 1220 | + while (i > 0 && (mul *= 0x100)) { | ||
| 1221 | + val += this[offset + --i] * mul | ||
| 1222 | + } | ||
| 1223 | + mul *= 0x80 | ||
| 1224 | + | ||
| 1225 | + if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
| 1226 | + | ||
| 1227 | + return val | ||
| 1228 | +} | ||
| 1229 | + | ||
| 1230 | +Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { | ||
| 1231 | + offset = offset >>> 0 | ||
| 1232 | + if (!noAssert) checkOffset(offset, 1, this.length) | ||
| 1233 | + if (!(this[offset] & 0x80)) return (this[offset]) | ||
| 1234 | + return ((0xff - this[offset] + 1) * -1) | ||
| 1235 | +} | ||
| 1236 | + | ||
| 1237 | +Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { | ||
| 1238 | + offset = offset >>> 0 | ||
| 1239 | + if (!noAssert) checkOffset(offset, 2, this.length) | ||
| 1240 | + var val = this[offset] | (this[offset + 1] << 8) | ||
| 1241 | + return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
| 1242 | +} | ||
| 1243 | + | ||
| 1244 | +Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { | ||
| 1245 | + offset = offset >>> 0 | ||
| 1246 | + if (!noAssert) checkOffset(offset, 2, this.length) | ||
| 1247 | + var val = this[offset + 1] | (this[offset] << 8) | ||
| 1248 | + return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
| 1249 | +} | ||
| 1250 | + | ||
| 1251 | +Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { | ||
| 1252 | + offset = offset >>> 0 | ||
| 1253 | + if (!noAssert) checkOffset(offset, 4, this.length) | ||
| 1254 | + | ||
| 1255 | + return (this[offset]) | | ||
| 1256 | + (this[offset + 1] << 8) | | ||
| 1257 | + (this[offset + 2] << 16) | | ||
| 1258 | + (this[offset + 3] << 24) | ||
| 1259 | +} | ||
| 1260 | + | ||
| 1261 | +Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { | ||
| 1262 | + offset = offset >>> 0 | ||
| 1263 | + if (!noAssert) checkOffset(offset, 4, this.length) | ||
| 1264 | + | ||
| 1265 | + return (this[offset] << 24) | | ||
| 1266 | + (this[offset + 1] << 16) | | ||
| 1267 | + (this[offset + 2] << 8) | | ||
| 1268 | + (this[offset + 3]) | ||
| 1269 | +} | ||
| 1270 | + | ||
| 1271 | +Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { | ||
| 1272 | + offset = offset >>> 0 | ||
| 1273 | + if (!noAssert) checkOffset(offset, 4, this.length) | ||
| 1274 | + return ieee754.read(this, offset, true, 23, 4) | ||
| 1275 | +} | ||
| 1276 | + | ||
| 1277 | +Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { | ||
| 1278 | + offset = offset >>> 0 | ||
| 1279 | + if (!noAssert) checkOffset(offset, 4, this.length) | ||
| 1280 | + return ieee754.read(this, offset, false, 23, 4) | ||
| 1281 | +} | ||
| 1282 | + | ||
| 1283 | +Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { | ||
| 1284 | + offset = offset >>> 0 | ||
| 1285 | + if (!noAssert) checkOffset(offset, 8, this.length) | ||
| 1286 | + return ieee754.read(this, offset, true, 52, 8) | ||
| 1287 | +} | ||
| 1288 | + | ||
| 1289 | +Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { | ||
| 1290 | + offset = offset >>> 0 | ||
| 1291 | + if (!noAssert) checkOffset(offset, 8, this.length) | ||
| 1292 | + return ieee754.read(this, offset, false, 52, 8) | ||
| 1293 | +} | ||
| 1294 | + | ||
| 1295 | +function checkInt(buf, value, offset, ext, max, min) { | ||
| 1296 | + if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') | ||
| 1297 | + if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') | ||
| 1298 | + if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
| 1299 | +} | ||
| 1300 | + | ||
| 1301 | +Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { | ||
| 1302 | + value = +value | ||
| 1303 | + offset = offset >>> 0 | ||
| 1304 | + byteLength = byteLength >>> 0 | ||
| 1305 | + if (!noAssert) { | ||
| 1306 | + var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
| 1307 | + checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
| 1308 | + } | ||
| 1309 | + | ||
| 1310 | + var mul = 1 | ||
| 1311 | + var i = 0 | ||
| 1312 | + this[offset] = value & 0xFF | ||
| 1313 | + while (++i < byteLength && (mul *= 0x100)) { | ||
| 1314 | + this[offset + i] = (value / mul) & 0xFF | ||
| 1315 | + } | ||
| 1316 | + | ||
| 1317 | + return offset + byteLength | ||
| 1318 | +} | ||
| 1319 | + | ||
| 1320 | +Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { | ||
| 1321 | + value = +value | ||
| 1322 | + offset = offset >>> 0 | ||
| 1323 | + byteLength = byteLength >>> 0 | ||
| 1324 | + if (!noAssert) { | ||
| 1325 | + var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
| 1326 | + checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
| 1327 | + } | ||
| 1328 | + | ||
| 1329 | + var i = byteLength - 1 | ||
| 1330 | + var mul = 1 | ||
| 1331 | + this[offset + i] = value & 0xFF | ||
| 1332 | + while (--i >= 0 && (mul *= 0x100)) { | ||
| 1333 | + this[offset + i] = (value / mul) & 0xFF | ||
| 1334 | + } | ||
| 1335 | + | ||
| 1336 | + return offset + byteLength | ||
| 1337 | +} | ||
| 1338 | + | ||
| 1339 | +Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { | ||
| 1340 | + value = +value | ||
| 1341 | + offset = offset >>> 0 | ||
| 1342 | + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) | ||
| 1343 | + this[offset] = (value & 0xff) | ||
| 1344 | + return offset + 1 | ||
| 1345 | +} | ||
| 1346 | + | ||
| 1347 | +Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { | ||
| 1348 | + value = +value | ||
| 1349 | + offset = offset >>> 0 | ||
| 1350 | + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
| 1351 | + this[offset] = (value & 0xff) | ||
| 1352 | + this[offset + 1] = (value >>> 8) | ||
| 1353 | + return offset + 2 | ||
| 1354 | +} | ||
| 1355 | + | ||
| 1356 | +Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { | ||
| 1357 | + value = +value | ||
| 1358 | + offset = offset >>> 0 | ||
| 1359 | + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
| 1360 | + this[offset] = (value >>> 8) | ||
| 1361 | + this[offset + 1] = (value & 0xff) | ||
| 1362 | + return offset + 2 | ||
| 1363 | +} | ||
| 1364 | + | ||
| 1365 | +Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { | ||
| 1366 | + value = +value | ||
| 1367 | + offset = offset >>> 0 | ||
| 1368 | + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
| 1369 | + this[offset + 3] = (value >>> 24) | ||
| 1370 | + this[offset + 2] = (value >>> 16) | ||
| 1371 | + this[offset + 1] = (value >>> 8) | ||
| 1372 | + this[offset] = (value & 0xff) | ||
| 1373 | + return offset + 4 | ||
| 1374 | +} | ||
| 1375 | + | ||
| 1376 | +Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { | ||
| 1377 | + value = +value | ||
| 1378 | + offset = offset >>> 0 | ||
| 1379 | + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
| 1380 | + this[offset] = (value >>> 24) | ||
| 1381 | + this[offset + 1] = (value >>> 16) | ||
| 1382 | + this[offset + 2] = (value >>> 8) | ||
| 1383 | + this[offset + 3] = (value & 0xff) | ||
| 1384 | + return offset + 4 | ||
| 1385 | +} | ||
| 1386 | + | ||
| 1387 | +Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { | ||
| 1388 | + value = +value | ||
| 1389 | + offset = offset >>> 0 | ||
| 1390 | + if (!noAssert) { | ||
| 1391 | + var limit = Math.pow(2, (8 * byteLength) - 1) | ||
| 1392 | + | ||
| 1393 | + checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
| 1394 | + } | ||
| 1395 | + | ||
| 1396 | + var i = 0 | ||
| 1397 | + var mul = 1 | ||
| 1398 | + var sub = 0 | ||
| 1399 | + this[offset] = value & 0xFF | ||
| 1400 | + while (++i < byteLength && (mul *= 0x100)) { | ||
| 1401 | + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { | ||
| 1402 | + sub = 1 | ||
| 1403 | + } | ||
| 1404 | + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
| 1405 | + } | ||
| 1406 | + | ||
| 1407 | + return offset + byteLength | ||
| 1408 | +} | ||
| 1409 | + | ||
| 1410 | +Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { | ||
| 1411 | + value = +value | ||
| 1412 | + offset = offset >>> 0 | ||
| 1413 | + if (!noAssert) { | ||
| 1414 | + var limit = Math.pow(2, (8 * byteLength) - 1) | ||
| 1415 | + | ||
| 1416 | + checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
| 1417 | + } | ||
| 1418 | + | ||
| 1419 | + var i = byteLength - 1 | ||
| 1420 | + var mul = 1 | ||
| 1421 | + var sub = 0 | ||
| 1422 | + this[offset + i] = value & 0xFF | ||
| 1423 | + while (--i >= 0 && (mul *= 0x100)) { | ||
| 1424 | + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { | ||
| 1425 | + sub = 1 | ||
| 1426 | + } | ||
| 1427 | + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
| 1428 | + } | ||
| 1429 | + | ||
| 1430 | + return offset + byteLength | ||
| 1431 | +} | ||
| 1432 | + | ||
| 1433 | +Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { | ||
| 1434 | + value = +value | ||
| 1435 | + offset = offset >>> 0 | ||
| 1436 | + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) | ||
| 1437 | + if (value < 0) value = 0xff + value + 1 | ||
| 1438 | + this[offset] = (value & 0xff) | ||
| 1439 | + return offset + 1 | ||
| 1440 | +} | ||
| 1441 | + | ||
| 1442 | +Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { | ||
| 1443 | + value = +value | ||
| 1444 | + offset = offset >>> 0 | ||
| 1445 | + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
| 1446 | + this[offset] = (value & 0xff) | ||
| 1447 | + this[offset + 1] = (value >>> 8) | ||
| 1448 | + return offset + 2 | ||
| 1449 | +} | ||
| 1450 | + | ||
| 1451 | +Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { | ||
| 1452 | + value = +value | ||
| 1453 | + offset = offset >>> 0 | ||
| 1454 | + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
| 1455 | + this[offset] = (value >>> 8) | ||
| 1456 | + this[offset + 1] = (value & 0xff) | ||
| 1457 | + return offset + 2 | ||
| 1458 | +} | ||
| 1459 | + | ||
| 1460 | +Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { | ||
| 1461 | + value = +value | ||
| 1462 | + offset = offset >>> 0 | ||
| 1463 | + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
| 1464 | + this[offset] = (value & 0xff) | ||
| 1465 | + this[offset + 1] = (value >>> 8) | ||
| 1466 | + this[offset + 2] = (value >>> 16) | ||
| 1467 | + this[offset + 3] = (value >>> 24) | ||
| 1468 | + return offset + 4 | ||
| 1469 | +} | ||
| 1470 | + | ||
| 1471 | +Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { | ||
| 1472 | + value = +value | ||
| 1473 | + offset = offset >>> 0 | ||
| 1474 | + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
| 1475 | + if (value < 0) value = 0xffffffff + value + 1 | ||
| 1476 | + this[offset] = (value >>> 24) | ||
| 1477 | + this[offset + 1] = (value >>> 16) | ||
| 1478 | + this[offset + 2] = (value >>> 8) | ||
| 1479 | + this[offset + 3] = (value & 0xff) | ||
| 1480 | + return offset + 4 | ||
| 1481 | +} | ||
| 1482 | + | ||
| 1483 | +function checkIEEE754(buf, value, offset, ext, max, min) { | ||
| 1484 | + if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
| 1485 | + if (offset < 0) throw new RangeError('Index out of range') | ||
| 1486 | +} | ||
| 1487 | + | ||
| 1488 | +function writeFloat(buf, value, offset, littleEndian, noAssert) { | ||
| 1489 | + value = +value | ||
| 1490 | + offset = offset >>> 0 | ||
| 1491 | + if (!noAssert) { | ||
| 1492 | + checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) | ||
| 1493 | + } | ||
| 1494 | + ieee754.write(buf, value, offset, littleEndian, 23, 4) | ||
| 1495 | + return offset + 4 | ||
| 1496 | +} | ||
| 1497 | + | ||
| 1498 | +Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { | ||
| 1499 | + return writeFloat(this, value, offset, true, noAssert) | ||
| 1500 | +} | ||
| 1501 | + | ||
| 1502 | +Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { | ||
| 1503 | + return writeFloat(this, value, offset, false, noAssert) | ||
| 1504 | +} | ||
| 1505 | + | ||
| 1506 | +function writeDouble(buf, value, offset, littleEndian, noAssert) { | ||
| 1507 | + value = +value | ||
| 1508 | + offset = offset >>> 0 | ||
| 1509 | + if (!noAssert) { | ||
| 1510 | + checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) | ||
| 1511 | + } | ||
| 1512 | + ieee754.write(buf, value, offset, littleEndian, 52, 8) | ||
| 1513 | + return offset + 8 | ||
| 1514 | +} | ||
| 1515 | + | ||
| 1516 | +Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { | ||
| 1517 | + return writeDouble(this, value, offset, true, noAssert) | ||
| 1518 | +} | ||
| 1519 | + | ||
| 1520 | +Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { | ||
| 1521 | + return writeDouble(this, value, offset, false, noAssert) | ||
| 1522 | +} | ||
| 1523 | + | ||
| 1524 | +// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
| 1525 | +Buffer.prototype.copy = function copy(target, targetStart, start, end) { | ||
| 1526 | + if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer') | ||
| 1527 | + if (!start) start = 0 | ||
| 1528 | + if (!end && end !== 0) end = this.length | ||
| 1529 | + if (targetStart >= target.length) targetStart = target.length | ||
| 1530 | + if (!targetStart) targetStart = 0 | ||
| 1531 | + if (end > 0 && end < start) end = start | ||
| 1532 | + | ||
| 1533 | + // Copy 0 bytes; we're done | ||
| 1534 | + if (end === start) return 0 | ||
| 1535 | + if (target.length === 0 || this.length === 0) return 0 | ||
| 1536 | + | ||
| 1537 | + // Fatal error conditions | ||
| 1538 | + if (targetStart < 0) { | ||
| 1539 | + throw new RangeError('targetStart out of bounds') | ||
| 1540 | + } | ||
| 1541 | + if (start < 0 || start >= this.length) throw new RangeError('Index out of range') | ||
| 1542 | + if (end < 0) throw new RangeError('sourceEnd out of bounds') | ||
| 1543 | + | ||
| 1544 | + // Are we oob? | ||
| 1545 | + if (end > this.length) end = this.length | ||
| 1546 | + if (target.length - targetStart < end - start) { | ||
| 1547 | + end = target.length - targetStart + start | ||
| 1548 | + } | ||
| 1549 | + | ||
| 1550 | + var len = end - start | ||
| 1551 | + | ||
| 1552 | + if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { | ||
| 1553 | + // Use built-in when available, missing from IE11 | ||
| 1554 | + this.copyWithin(targetStart, start, end) | ||
| 1555 | + } else if (this === target && start < targetStart && targetStart < end) { | ||
| 1556 | + // descending copy from end | ||
| 1557 | + for (var i = len - 1; i >= 0; --i) { | ||
| 1558 | + target[i + targetStart] = this[i + start] | ||
| 1559 | + } | ||
| 1560 | + } else { | ||
| 1561 | + Uint8Array.prototype.set.call( | ||
| 1562 | + target, | ||
| 1563 | + this.subarray(start, end), | ||
| 1564 | + targetStart | ||
| 1565 | + ) | ||
| 1566 | + } | ||
| 1567 | + | ||
| 1568 | + return len | ||
| 1569 | +} | ||
| 1570 | + | ||
| 1571 | +// Usage: | ||
| 1572 | +// buffer.fill(number[, offset[, end]]) | ||
| 1573 | +// buffer.fill(buffer[, offset[, end]]) | ||
| 1574 | +// buffer.fill(string[, offset[, end]][, encoding]) | ||
| 1575 | +Buffer.prototype.fill = function fill(val, start, end, encoding) { | ||
| 1576 | + // Handle string cases: | ||
| 1577 | + if (typeof val === 'string') { | ||
| 1578 | + if (typeof start === 'string') { | ||
| 1579 | + encoding = start | ||
| 1580 | + start = 0 | ||
| 1581 | + end = this.length | ||
| 1582 | + } else if (typeof end === 'string') { | ||
| 1583 | + encoding = end | ||
| 1584 | + end = this.length | ||
| 1585 | + } | ||
| 1586 | + if (encoding !== undefined && typeof encoding !== 'string') { | ||
| 1587 | + throw new TypeError('encoding must be a string') | ||
| 1588 | + } | ||
| 1589 | + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { | ||
| 1590 | + throw new TypeError('Unknown encoding: ' + encoding) | ||
| 1591 | + } | ||
| 1592 | + if (val.length === 1) { | ||
| 1593 | + var code = val.charCodeAt(0) | ||
| 1594 | + if ((encoding === 'utf8' && code < 128) || | ||
| 1595 | + encoding === 'latin1') { | ||
| 1596 | + // Fast path: If `val` fits into a single byte, use that numeric value. | ||
| 1597 | + val = code | ||
| 1598 | + } | ||
| 1599 | + } | ||
| 1600 | + } else if (typeof val === 'number') { | ||
| 1601 | + val = val & 255 | ||
| 1602 | + } else if (typeof val === 'boolean') { | ||
| 1603 | + val = Number(val) | ||
| 1604 | + } | ||
| 1605 | + | ||
| 1606 | + // Invalid ranges are not set to a default, so can range check early. | ||
| 1607 | + if (start < 0 || this.length < start || this.length < end) { | ||
| 1608 | + throw new RangeError('Out of range index') | ||
| 1609 | + } | ||
| 1610 | + | ||
| 1611 | + if (end <= start) { | ||
| 1612 | + return this | ||
| 1613 | + } | ||
| 1614 | + | ||
| 1615 | + start = start >>> 0 | ||
| 1616 | + end = end === undefined ? this.length : end >>> 0 | ||
| 1617 | + | ||
| 1618 | + if (!val) val = 0 | ||
| 1619 | + | ||
| 1620 | + var i | ||
| 1621 | + if (typeof val === 'number') { | ||
| 1622 | + for (i = start; i < end; ++i) { | ||
| 1623 | + this[i] = val | ||
| 1624 | + } | ||
| 1625 | + } else { | ||
| 1626 | + var bytes = Buffer.isBuffer(val) ? | ||
| 1627 | + val : | ||
| 1628 | + Buffer.from(val, encoding) | ||
| 1629 | + var len = bytes.length | ||
| 1630 | + if (len === 0) { | ||
| 1631 | + throw new TypeError('The value "' + val + | ||
| 1632 | + '" is invalid for argument "value"') | ||
| 1633 | + } | ||
| 1634 | + for (i = 0; i < end - start; ++i) { | ||
| 1635 | + this[i + start] = bytes[i % len] | ||
| 1636 | + } | ||
| 1637 | + } | ||
| 1638 | + | ||
| 1639 | + return this | ||
| 1640 | +} | ||
| 1641 | + | ||
| 1642 | +// HELPER FUNCTIONS | ||
| 1643 | +// ================ | ||
| 1644 | + | ||
| 1645 | +var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g | ||
| 1646 | + | ||
| 1647 | +function base64clean(str) { | ||
| 1648 | + // Node takes equal signs as end of the Base64 encoding | ||
| 1649 | + str = str.split('=')[0] | ||
| 1650 | + // Node strips out invalid characters like \n and \t from the string, base64-js does not | ||
| 1651 | + str = str.trim().replace(INVALID_BASE64_RE, '') | ||
| 1652 | + // Node converts strings with length < 2 to '' | ||
| 1653 | + if (str.length < 2) return '' | ||
| 1654 | + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not | ||
| 1655 | + while (str.length % 4 !== 0) { | ||
| 1656 | + str = str + '=' | ||
| 1657 | + } | ||
| 1658 | + return str | ||
| 1659 | +} | ||
| 1660 | + | ||
| 1661 | +function utf8ToBytes(string, units) { | ||
| 1662 | + units = units || Infinity | ||
| 1663 | + var codePoint | ||
| 1664 | + var length = string.length | ||
| 1665 | + var leadSurrogate = null | ||
| 1666 | + var bytes = [] | ||
| 1667 | + | ||
| 1668 | + for (var i = 0; i < length; ++i) { | ||
| 1669 | + codePoint = string.charCodeAt(i) | ||
| 1670 | + | ||
| 1671 | + // is surrogate component | ||
| 1672 | + if (codePoint > 0xD7FF && codePoint < 0xE000) { | ||
| 1673 | + // last char was a lead | ||
| 1674 | + if (!leadSurrogate) { | ||
| 1675 | + // no lead yet | ||
| 1676 | + if (codePoint > 0xDBFF) { | ||
| 1677 | + // unexpected trail | ||
| 1678 | + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
| 1679 | + continue | ||
| 1680 | + } else if (i + 1 === length) { | ||
| 1681 | + // unpaired lead | ||
| 1682 | + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
| 1683 | + continue | ||
| 1684 | + } | ||
| 1685 | + | ||
| 1686 | + // valid lead | ||
| 1687 | + leadSurrogate = codePoint | ||
| 1688 | + | ||
| 1689 | + continue | ||
| 1690 | + } | ||
| 1691 | + | ||
| 1692 | + // 2 leads in a row | ||
| 1693 | + if (codePoint < 0xDC00) { | ||
| 1694 | + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
| 1695 | + leadSurrogate = codePoint | ||
| 1696 | + continue | ||
| 1697 | + } | ||
| 1698 | + | ||
| 1699 | + // valid surrogate pair | ||
| 1700 | + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 | ||
| 1701 | + } else if (leadSurrogate) { | ||
| 1702 | + // valid bmp char, but last char was a lead | ||
| 1703 | + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
| 1704 | + } | ||
| 1705 | + | ||
| 1706 | + leadSurrogate = null | ||
| 1707 | + | ||
| 1708 | + // encode utf8 | ||
| 1709 | + if (codePoint < 0x80) { | ||
| 1710 | + if ((units -= 1) < 0) break | ||
| 1711 | + bytes.push(codePoint) | ||
| 1712 | + } else if (codePoint < 0x800) { | ||
| 1713 | + if ((units -= 2) < 0) break | ||
| 1714 | + bytes.push( | ||
| 1715 | + codePoint >> 0x6 | 0xC0, | ||
| 1716 | + codePoint & 0x3F | 0x80 | ||
| 1717 | + ) | ||
| 1718 | + } else if (codePoint < 0x10000) { | ||
| 1719 | + if ((units -= 3) < 0) break | ||
| 1720 | + bytes.push( | ||
| 1721 | + codePoint >> 0xC | 0xE0, | ||
| 1722 | + codePoint >> 0x6 & 0x3F | 0x80, | ||
| 1723 | + codePoint & 0x3F | 0x80 | ||
| 1724 | + ) | ||
| 1725 | + } else if (codePoint < 0x110000) { | ||
| 1726 | + if ((units -= 4) < 0) break | ||
| 1727 | + bytes.push( | ||
| 1728 | + codePoint >> 0x12 | 0xF0, | ||
| 1729 | + codePoint >> 0xC & 0x3F | 0x80, | ||
| 1730 | + codePoint >> 0x6 & 0x3F | 0x80, | ||
| 1731 | + codePoint & 0x3F | 0x80 | ||
| 1732 | + ) | ||
| 1733 | + } else { | ||
| 1734 | + throw new Error('Invalid code point') | ||
| 1735 | + } | ||
| 1736 | + } | ||
| 1737 | + | ||
| 1738 | + return bytes | ||
| 1739 | +} | ||
| 1740 | + | ||
| 1741 | +function asciiToBytes(str) { | ||
| 1742 | + var byteArray = [] | ||
| 1743 | + for (var i = 0; i < str.length; ++i) { | ||
| 1744 | + // Node's code seems to be doing this and not & 0x7F.. | ||
| 1745 | + byteArray.push(str.charCodeAt(i) & 0xFF) | ||
| 1746 | + } | ||
| 1747 | + return byteArray | ||
| 1748 | +} | ||
| 1749 | + | ||
| 1750 | +function utf16leToBytes(str, units) { | ||
| 1751 | + var c, hi, lo | ||
| 1752 | + var byteArray = [] | ||
| 1753 | + for (var i = 0; i < str.length; ++i) { | ||
| 1754 | + if ((units -= 2) < 0) break | ||
| 1755 | + | ||
| 1756 | + c = str.charCodeAt(i) | ||
| 1757 | + hi = c >> 8 | ||
| 1758 | + lo = c % 256 | ||
| 1759 | + byteArray.push(lo) | ||
| 1760 | + byteArray.push(hi) | ||
| 1761 | + } | ||
| 1762 | + | ||
| 1763 | + return byteArray | ||
| 1764 | +} | ||
| 1765 | + | ||
| 1766 | +function base64ToBytes(str) { | ||
| 1767 | + return base64.toByteArray(base64clean(str)) | ||
| 1768 | +} | ||
| 1769 | + | ||
| 1770 | +function blitBuffer(src, dst, offset, length) { | ||
| 1771 | + for (var i = 0; i < length; ++i) { | ||
| 1772 | + if ((i + offset >= dst.length) || (i >= src.length)) break | ||
| 1773 | + dst[i + offset] = src[i] | ||
| 1774 | + } | ||
| 1775 | + return i | ||
| 1776 | +} | ||
| 1777 | + | ||
| 1778 | +// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass | ||
| 1779 | +// the `instanceof` check but they should be treated as of that type. | ||
| 1780 | +// See: https://github.com/feross/buffer/issues/166 | ||
| 1781 | +function isInstance(obj, type) { | ||
| 1782 | + return obj instanceof type || | ||
| 1783 | + (obj != null && obj.constructor != null && obj.constructor.name != null && | ||
| 1784 | + obj.constructor.name === type.name) | ||
| 1785 | +} | ||
| 1786 | + | ||
| 1787 | +function numberIsNaN(obj) { | ||
| 1788 | + // For IE11 support | ||
| 1789 | + return obj !== obj // eslint-disable-line no-self-compare | ||
| 1790 | +} | ||
| 1791 | + | ||
| 1792 | +// Create lookup table for `toString('hex')` | ||
| 1793 | +// See: https://github.com/feross/buffer/issues/219 | ||
| 1794 | +var hexSliceLookupTable = (function () { | ||
| 1795 | + var alphabet = '0123456789abcdef' | ||
| 1796 | + var table = new Array(256) | ||
| 1797 | + for (var i = 0; i < 16; ++i) { | ||
| 1798 | + var i16 = i * 16 | ||
| 1799 | + for (var j = 0; j < 16; ++j) { | ||
| 1800 | + table[i16 + j] = alphabet[i] + alphabet[j] | ||
| 1801 | + } | ||
| 1802 | + } | ||
| 1803 | + return table | ||
| 1804 | +})() | ||
| 1805 | +module.exports = Buffer; |
miniprogram/utils/copyto/core.js
0 → 100644
| 1 | +; | ||
| 2 | +(function (root, factory) { | ||
| 3 | + if (typeof exports === "object") { | ||
| 4 | + // CommonJS | ||
| 5 | + module.exports = exports = factory(); | ||
| 6 | + } else if (typeof define === "function" && define.amd) { | ||
| 7 | + // AMD | ||
| 8 | + define([], factory); | ||
| 9 | + } else { | ||
| 10 | + // Global (browser) | ||
| 11 | + root.CryptoJS = factory(); | ||
| 12 | + } | ||
| 13 | +}(this, function () { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * CryptoJS core components. | ||
| 17 | + */ | ||
| 18 | + var CryptoJS = CryptoJS || (function (Math, undefined) { | ||
| 19 | + /* | ||
| 20 | + * Local polyfil of Object.create | ||
| 21 | + */ | ||
| 22 | + var create = Object.create || (function () { | ||
| 23 | + function F() {}; | ||
| 24 | + | ||
| 25 | + return function (obj) { | ||
| 26 | + var subtype; | ||
| 27 | + | ||
| 28 | + F.prototype = obj; | ||
| 29 | + | ||
| 30 | + subtype = new F(); | ||
| 31 | + | ||
| 32 | + F.prototype = null; | ||
| 33 | + | ||
| 34 | + return subtype; | ||
| 35 | + }; | ||
| 36 | + }()) | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * CryptoJS namespace. | ||
| 40 | + */ | ||
| 41 | + var C = {}; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Library namespace. | ||
| 45 | + */ | ||
| 46 | + var C_lib = C.lib = {}; | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Base object for prototypal inheritance. | ||
| 50 | + */ | ||
| 51 | + var Base = C_lib.Base = (function () { | ||
| 52 | + | ||
| 53 | + | ||
| 54 | + return { | ||
| 55 | + /** | ||
| 56 | + * Creates a new object that inherits from this object. | ||
| 57 | + * | ||
| 58 | + * @param {Object} overrides Properties to copy into the new object. | ||
| 59 | + * | ||
| 60 | + * @return {Object} The new object. | ||
| 61 | + * | ||
| 62 | + * @static | ||
| 63 | + * | ||
| 64 | + * @example | ||
| 65 | + * | ||
| 66 | + * var MyType = CryptoJS.lib.Base.extend({ | ||
| 67 | + * field: 'value', | ||
| 68 | + * | ||
| 69 | + * method: function () { | ||
| 70 | + * } | ||
| 71 | + * }); | ||
| 72 | + */ | ||
| 73 | + extend: function (overrides) { | ||
| 74 | + // Spawn | ||
| 75 | + var subtype = create(this); | ||
| 76 | + | ||
| 77 | + // Augment | ||
| 78 | + if (overrides) { | ||
| 79 | + subtype.mixIn(overrides); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + // Create default initializer | ||
| 83 | + if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { | ||
| 84 | + subtype.init = function () { | ||
| 85 | + subtype.$super.init.apply(this, arguments); | ||
| 86 | + }; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + // Initializer's prototype is the subtype object | ||
| 90 | + subtype.init.prototype = subtype; | ||
| 91 | + | ||
| 92 | + // Reference supertype | ||
| 93 | + subtype.$super = this; | ||
| 94 | + | ||
| 95 | + return subtype; | ||
| 96 | + }, | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * Extends this object and runs the init method. | ||
| 100 | + * Arguments to create() will be passed to init(). | ||
| 101 | + * | ||
| 102 | + * @return {Object} The new object. | ||
| 103 | + * | ||
| 104 | + * @static | ||
| 105 | + * | ||
| 106 | + * @example | ||
| 107 | + * | ||
| 108 | + * var instance = MyType.create(); | ||
| 109 | + */ | ||
| 110 | + create: function () { | ||
| 111 | + var instance = this.extend(); | ||
| 112 | + instance.init.apply(instance, arguments); | ||
| 113 | + | ||
| 114 | + return instance; | ||
| 115 | + }, | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * Initializes a newly created object. | ||
| 119 | + * Override this method to add some logic when your objects are created. | ||
| 120 | + * | ||
| 121 | + * @example | ||
| 122 | + * | ||
| 123 | + * var MyType = CryptoJS.lib.Base.extend({ | ||
| 124 | + * init: function () { | ||
| 125 | + * // ... | ||
| 126 | + * } | ||
| 127 | + * }); | ||
| 128 | + */ | ||
| 129 | + init: function () {}, | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * Copies properties into this object. | ||
| 133 | + * | ||
| 134 | + * @param {Object} properties The properties to mix in. | ||
| 135 | + * | ||
| 136 | + * @example | ||
| 137 | + * | ||
| 138 | + * MyType.mixIn({ | ||
| 139 | + * field: 'value' | ||
| 140 | + * }); | ||
| 141 | + */ | ||
| 142 | + mixIn: function (properties) { | ||
| 143 | + for (var propertyName in properties) { | ||
| 144 | + if (properties.hasOwnProperty(propertyName)) { | ||
| 145 | + this[propertyName] = properties[propertyName]; | ||
| 146 | + } | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + // IE won't copy toString using the loop above | ||
| 150 | + if (properties.hasOwnProperty('toString')) { | ||
| 151 | + this.toString = properties.toString; | ||
| 152 | + } | ||
| 153 | + }, | ||
| 154 | + | ||
| 155 | + /** | ||
| 156 | + * Creates a copy of this object. | ||
| 157 | + * | ||
| 158 | + * @return {Object} The clone. | ||
| 159 | + * | ||
| 160 | + * @example | ||
| 161 | + * | ||
| 162 | + * var clone = instance.clone(); | ||
| 163 | + */ | ||
| 164 | + clone: function () { | ||
| 165 | + return this.init.prototype.extend(this); | ||
| 166 | + } | ||
| 167 | + }; | ||
| 168 | + }()); | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * An array of 32-bit words. | ||
| 172 | + * | ||
| 173 | + * @property {Array} words The array of 32-bit words. | ||
| 174 | + * @property {number} sigBytes The number of significant bytes in this word array. | ||
| 175 | + */ | ||
| 176 | + var WordArray = C_lib.WordArray = Base.extend({ | ||
| 177 | + /** | ||
| 178 | + * Initializes a newly created word array. | ||
| 179 | + * | ||
| 180 | + * @param {Array} words (Optional) An array of 32-bit words. | ||
| 181 | + * @param {number} sigBytes (Optional) The number of significant bytes in the words. | ||
| 182 | + * | ||
| 183 | + * @example | ||
| 184 | + * | ||
| 185 | + * var wordArray = CryptoJS.lib.WordArray.create(); | ||
| 186 | + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); | ||
| 187 | + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); | ||
| 188 | + */ | ||
| 189 | + init: function (words, sigBytes) { | ||
| 190 | + words = this.words = words || []; | ||
| 191 | + | ||
| 192 | + if (sigBytes != undefined) { | ||
| 193 | + this.sigBytes = sigBytes; | ||
| 194 | + } else { | ||
| 195 | + this.sigBytes = words.length * 4; | ||
| 196 | + } | ||
| 197 | + }, | ||
| 198 | + | ||
| 199 | + /** | ||
| 200 | + * Converts this word array to a string. | ||
| 201 | + * | ||
| 202 | + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex | ||
| 203 | + * | ||
| 204 | + * @return {string} The stringified word array. | ||
| 205 | + * | ||
| 206 | + * @example | ||
| 207 | + * | ||
| 208 | + * var string = wordArray + ''; | ||
| 209 | + * var string = wordArray.toString(); | ||
| 210 | + * var string = wordArray.toString(CryptoJS.enc.Utf8); | ||
| 211 | + */ | ||
| 212 | + toString: function (encoder) { | ||
| 213 | + return (encoder || Hex).stringify(this); | ||
| 214 | + }, | ||
| 215 | + | ||
| 216 | + /** | ||
| 217 | + * Concatenates a word array to this word array. | ||
| 218 | + * | ||
| 219 | + * @param {WordArray} wordArray The word array to append. | ||
| 220 | + * | ||
| 221 | + * @return {WordArray} This word array. | ||
| 222 | + * | ||
| 223 | + * @example | ||
| 224 | + * | ||
| 225 | + * wordArray1.concat(wordArray2); | ||
| 226 | + */ | ||
| 227 | + concat: function (wordArray) { | ||
| 228 | + // Shortcuts | ||
| 229 | + var thisWords = this.words; | ||
| 230 | + var thatWords = wordArray.words; | ||
| 231 | + var thisSigBytes = this.sigBytes; | ||
| 232 | + var thatSigBytes = wordArray.sigBytes; | ||
| 233 | + | ||
| 234 | + // Clamp excess bits | ||
| 235 | + this.clamp(); | ||
| 236 | + | ||
| 237 | + // Concat | ||
| 238 | + if (thisSigBytes % 4) { | ||
| 239 | + // Copy one byte at a time | ||
| 240 | + for (var i = 0; i < thatSigBytes; i++) { | ||
| 241 | + var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
| 242 | + thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); | ||
| 243 | + } | ||
| 244 | + } else { | ||
| 245 | + // Copy one word at a time | ||
| 246 | + for (var i = 0; i < thatSigBytes; i += 4) { | ||
| 247 | + thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; | ||
| 248 | + } | ||
| 249 | + } | ||
| 250 | + this.sigBytes += thatSigBytes; | ||
| 251 | + | ||
| 252 | + // Chainable | ||
| 253 | + return this; | ||
| 254 | + }, | ||
| 255 | + | ||
| 256 | + /** | ||
| 257 | + * Removes insignificant bits. | ||
| 258 | + * | ||
| 259 | + * @example | ||
| 260 | + * | ||
| 261 | + * wordArray.clamp(); | ||
| 262 | + */ | ||
| 263 | + clamp: function () { | ||
| 264 | + // Shortcuts | ||
| 265 | + var words = this.words; | ||
| 266 | + var sigBytes = this.sigBytes; | ||
| 267 | + | ||
| 268 | + // Clamp | ||
| 269 | + words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); | ||
| 270 | + words.length = Math.ceil(sigBytes / 4); | ||
| 271 | + }, | ||
| 272 | + | ||
| 273 | + /** | ||
| 274 | + * Creates a copy of this word array. | ||
| 275 | + * | ||
| 276 | + * @return {WordArray} The clone. | ||
| 277 | + * | ||
| 278 | + * @example | ||
| 279 | + * | ||
| 280 | + * var clone = wordArray.clone(); | ||
| 281 | + */ | ||
| 282 | + clone: function () { | ||
| 283 | + var clone = Base.clone.call(this); | ||
| 284 | + clone.words = this.words.slice(0); | ||
| 285 | + | ||
| 286 | + return clone; | ||
| 287 | + }, | ||
| 288 | + | ||
| 289 | + /** | ||
| 290 | + * Creates a word array filled with random bytes. | ||
| 291 | + * | ||
| 292 | + * @param {number} nBytes The number of random bytes to generate. | ||
| 293 | + * | ||
| 294 | + * @return {WordArray} The random word array. | ||
| 295 | + * | ||
| 296 | + * @static | ||
| 297 | + * | ||
| 298 | + * @example | ||
| 299 | + * | ||
| 300 | + * var wordArray = CryptoJS.lib.WordArray.random(16); | ||
| 301 | + */ | ||
| 302 | + random: function (nBytes) { | ||
| 303 | + var words = []; | ||
| 304 | + | ||
| 305 | + var r = (function (m_w) { | ||
| 306 | + var m_w = m_w; | ||
| 307 | + var m_z = 0x3ade68b1; | ||
| 308 | + var mask = 0xffffffff; | ||
| 309 | + | ||
| 310 | + return function () { | ||
| 311 | + m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; | ||
| 312 | + m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; | ||
| 313 | + var result = ((m_z << 0x10) + m_w) & mask; | ||
| 314 | + result /= 0x100000000; | ||
| 315 | + result += 0.5; | ||
| 316 | + return result * (Math.random() > .5 ? 1 : -1); | ||
| 317 | + } | ||
| 318 | + }); | ||
| 319 | + | ||
| 320 | + for (var i = 0, rcache; i < nBytes; i += 4) { | ||
| 321 | + var _r = r((rcache || Math.random()) * 0x100000000); | ||
| 322 | + | ||
| 323 | + rcache = _r() * 0x3ade67b7; | ||
| 324 | + words.push((_r() * 0x100000000) | 0); | ||
| 325 | + } | ||
| 326 | + | ||
| 327 | + return new WordArray.init(words, nBytes); | ||
| 328 | + } | ||
| 329 | + }); | ||
| 330 | + | ||
| 331 | + /** | ||
| 332 | + * Encoder namespace. | ||
| 333 | + */ | ||
| 334 | + var C_enc = C.enc = {}; | ||
| 335 | + | ||
| 336 | + /** | ||
| 337 | + * Hex encoding strategy. | ||
| 338 | + */ | ||
| 339 | + var Hex = C_enc.Hex = { | ||
| 340 | + /** | ||
| 341 | + * Converts a word array to a hex string. | ||
| 342 | + * | ||
| 343 | + * @param {WordArray} wordArray The word array. | ||
| 344 | + * | ||
| 345 | + * @return {string} The hex string. | ||
| 346 | + * | ||
| 347 | + * @static | ||
| 348 | + * | ||
| 349 | + * @example | ||
| 350 | + * | ||
| 351 | + * var hexString = CryptoJS.enc.Hex.stringify(wordArray); | ||
| 352 | + */ | ||
| 353 | + stringify: function (wordArray) { | ||
| 354 | + // Shortcuts | ||
| 355 | + var words = wordArray.words; | ||
| 356 | + var sigBytes = wordArray.sigBytes; | ||
| 357 | + | ||
| 358 | + // Convert | ||
| 359 | + var hexChars = []; | ||
| 360 | + for (var i = 0; i < sigBytes; i++) { | ||
| 361 | + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
| 362 | + hexChars.push((bite >>> 4).toString(16)); | ||
| 363 | + hexChars.push((bite & 0x0f).toString(16)); | ||
| 364 | + } | ||
| 365 | + | ||
| 366 | + return hexChars.join(''); | ||
| 367 | + }, | ||
| 368 | + | ||
| 369 | + /** | ||
| 370 | + * Converts a hex string to a word array. | ||
| 371 | + * | ||
| 372 | + * @param {string} hexStr The hex string. | ||
| 373 | + * | ||
| 374 | + * @return {WordArray} The word array. | ||
| 375 | + * | ||
| 376 | + * @static | ||
| 377 | + * | ||
| 378 | + * @example | ||
| 379 | + * | ||
| 380 | + * var wordArray = CryptoJS.enc.Hex.parse(hexString); | ||
| 381 | + */ | ||
| 382 | + parse: function (hexStr) { | ||
| 383 | + // Shortcut | ||
| 384 | + var hexStrLength = hexStr.length; | ||
| 385 | + | ||
| 386 | + // Convert | ||
| 387 | + var words = []; | ||
| 388 | + for (var i = 0; i < hexStrLength; i += 2) { | ||
| 389 | + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); | ||
| 390 | + } | ||
| 391 | + | ||
| 392 | + return new WordArray.init(words, hexStrLength / 2); | ||
| 393 | + } | ||
| 394 | + }; | ||
| 395 | + | ||
| 396 | + /** | ||
| 397 | + * Latin1 encoding strategy. | ||
| 398 | + */ | ||
| 399 | + var Latin1 = C_enc.Latin1 = { | ||
| 400 | + /** | ||
| 401 | + * Converts a word array to a Latin1 string. | ||
| 402 | + * | ||
| 403 | + * @param {WordArray} wordArray The word array. | ||
| 404 | + * | ||
| 405 | + * @return {string} The Latin1 string. | ||
| 406 | + * | ||
| 407 | + * @static | ||
| 408 | + * | ||
| 409 | + * @example | ||
| 410 | + * | ||
| 411 | + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); | ||
| 412 | + */ | ||
| 413 | + stringify: function (wordArray) { | ||
| 414 | + // Shortcuts | ||
| 415 | + var words = wordArray.words; | ||
| 416 | + var sigBytes = wordArray.sigBytes; | ||
| 417 | + | ||
| 418 | + // Convert | ||
| 419 | + var latin1Chars = []; | ||
| 420 | + for (var i = 0; i < sigBytes; i++) { | ||
| 421 | + var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
| 422 | + latin1Chars.push(String.fromCharCode(bite)); | ||
| 423 | + } | ||
| 424 | + | ||
| 425 | + return latin1Chars.join(''); | ||
| 426 | + }, | ||
| 427 | + | ||
| 428 | + /** | ||
| 429 | + * Converts a Latin1 string to a word array. | ||
| 430 | + * | ||
| 431 | + * @param {string} latin1Str The Latin1 string. | ||
| 432 | + * | ||
| 433 | + * @return {WordArray} The word array. | ||
| 434 | + * | ||
| 435 | + * @static | ||
| 436 | + * | ||
| 437 | + * @example | ||
| 438 | + * | ||
| 439 | + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); | ||
| 440 | + */ | ||
| 441 | + parse: function (latin1Str) { | ||
| 442 | + // Shortcut | ||
| 443 | + var latin1StrLength = latin1Str.length; | ||
| 444 | + | ||
| 445 | + // Convert | ||
| 446 | + var words = []; | ||
| 447 | + for (var i = 0; i < latin1StrLength; i++) { | ||
| 448 | + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); | ||
| 449 | + } | ||
| 450 | + | ||
| 451 | + return new WordArray.init(words, latin1StrLength); | ||
| 452 | + } | ||
| 453 | + }; | ||
| 454 | + | ||
| 455 | + /** | ||
| 456 | + * UTF-8 encoding strategy. | ||
| 457 | + */ | ||
| 458 | + var Utf8 = C_enc.Utf8 = { | ||
| 459 | + /** | ||
| 460 | + * Converts a word array to a UTF-8 string. | ||
| 461 | + * | ||
| 462 | + * @param {WordArray} wordArray The word array. | ||
| 463 | + * | ||
| 464 | + * @return {string} The UTF-8 string. | ||
| 465 | + * | ||
| 466 | + * @static | ||
| 467 | + * | ||
| 468 | + * @example | ||
| 469 | + * | ||
| 470 | + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); | ||
| 471 | + */ | ||
| 472 | + stringify: function (wordArray) { | ||
| 473 | + try { | ||
| 474 | + return decodeURIComponent(escape(Latin1.stringify(wordArray))); | ||
| 475 | + } catch (e) { | ||
| 476 | + throw new Error('Malformed UTF-8 data'); | ||
| 477 | + } | ||
| 478 | + }, | ||
| 479 | + | ||
| 480 | + /** | ||
| 481 | + * Converts a UTF-8 string to a word array. | ||
| 482 | + * | ||
| 483 | + * @param {string} utf8Str The UTF-8 string. | ||
| 484 | + * | ||
| 485 | + * @return {WordArray} The word array. | ||
| 486 | + * | ||
| 487 | + * @static | ||
| 488 | + * | ||
| 489 | + * @example | ||
| 490 | + * | ||
| 491 | + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); | ||
| 492 | + */ | ||
| 493 | + parse: function (utf8Str) { | ||
| 494 | + return Latin1.parse(unescape(encodeURIComponent(utf8Str))); | ||
| 495 | + } | ||
| 496 | + }; | ||
| 497 | + | ||
| 498 | + /** | ||
| 499 | + * Abstract buffered block algorithm template. | ||
| 500 | + * | ||
| 501 | + * The property blockSize must be implemented in a concrete subtype. | ||
| 502 | + * | ||
| 503 | + * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 | ||
| 504 | + */ | ||
| 505 | + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ | ||
| 506 | + /** | ||
| 507 | + * Resets this block algorithm's data buffer to its initial state. | ||
| 508 | + * | ||
| 509 | + * @example | ||
| 510 | + * | ||
| 511 | + * bufferedBlockAlgorithm.reset(); | ||
| 512 | + */ | ||
| 513 | + reset: function () { | ||
| 514 | + // Initial values | ||
| 515 | + this._data = new WordArray.init(); | ||
| 516 | + this._nDataBytes = 0; | ||
| 517 | + }, | ||
| 518 | + | ||
| 519 | + /** | ||
| 520 | + * Adds new data to this block algorithm's buffer. | ||
| 521 | + * | ||
| 522 | + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. | ||
| 523 | + * | ||
| 524 | + * @example | ||
| 525 | + * | ||
| 526 | + * bufferedBlockAlgorithm._append('data'); | ||
| 527 | + * bufferedBlockAlgorithm._append(wordArray); | ||
| 528 | + */ | ||
| 529 | + _append: function (data) { | ||
| 530 | + // Convert string to WordArray, else assume WordArray already | ||
| 531 | + if (typeof data == 'string') { | ||
| 532 | + data = Utf8.parse(data); | ||
| 533 | + } | ||
| 534 | + | ||
| 535 | + // Append | ||
| 536 | + this._data.concat(data); | ||
| 537 | + this._nDataBytes += data.sigBytes; | ||
| 538 | + }, | ||
| 539 | + | ||
| 540 | + /** | ||
| 541 | + * Processes available data blocks. | ||
| 542 | + * | ||
| 543 | + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. | ||
| 544 | + * | ||
| 545 | + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. | ||
| 546 | + * | ||
| 547 | + * @return {WordArray} The processed data. | ||
| 548 | + * | ||
| 549 | + * @example | ||
| 550 | + * | ||
| 551 | + * var processedData = bufferedBlockAlgorithm._process(); | ||
| 552 | + * var processedData = bufferedBlockAlgorithm._process(!!'flush'); | ||
| 553 | + */ | ||
| 554 | + _process: function (doFlush) { | ||
| 555 | + // Shortcuts | ||
| 556 | + var data = this._data; | ||
| 557 | + var dataWords = data.words; | ||
| 558 | + var dataSigBytes = data.sigBytes; | ||
| 559 | + var blockSize = this.blockSize; | ||
| 560 | + var blockSizeBytes = blockSize * 4; | ||
| 561 | + | ||
| 562 | + // Count blocks ready | ||
| 563 | + var nBlocksReady = dataSigBytes / blockSizeBytes; | ||
| 564 | + if (doFlush) { | ||
| 565 | + // Round up to include partial blocks | ||
| 566 | + nBlocksReady = Math.ceil(nBlocksReady); | ||
| 567 | + } else { | ||
| 568 | + // Round down to include only full blocks, | ||
| 569 | + // less the number of blocks that must remain in the buffer | ||
| 570 | + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); | ||
| 571 | + } | ||
| 572 | + | ||
| 573 | + // Count words ready | ||
| 574 | + var nWordsReady = nBlocksReady * blockSize; | ||
| 575 | + | ||
| 576 | + // Count bytes ready | ||
| 577 | + var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); | ||
| 578 | + | ||
| 579 | + // Process blocks | ||
| 580 | + if (nWordsReady) { | ||
| 581 | + for (var offset = 0; offset < nWordsReady; offset += blockSize) { | ||
| 582 | + // Perform concrete-algorithm logic | ||
| 583 | + this._doProcessBlock(dataWords, offset); | ||
| 584 | + } | ||
| 585 | + | ||
| 586 | + // Remove processed words | ||
| 587 | + var processedWords = dataWords.splice(0, nWordsReady); | ||
| 588 | + data.sigBytes -= nBytesReady; | ||
| 589 | + } | ||
| 590 | + | ||
| 591 | + // Return processed words | ||
| 592 | + return new WordArray.init(processedWords, nBytesReady); | ||
| 593 | + }, | ||
| 594 | + | ||
| 595 | + /** | ||
| 596 | + * Creates a copy of this object. | ||
| 597 | + * | ||
| 598 | + * @return {Object} The clone. | ||
| 599 | + * | ||
| 600 | + * @example | ||
| 601 | + * | ||
| 602 | + * var clone = bufferedBlockAlgorithm.clone(); | ||
| 603 | + */ | ||
| 604 | + clone: function () { | ||
| 605 | + var clone = Base.clone.call(this); | ||
| 606 | + clone._data = this._data.clone(); | ||
| 607 | + | ||
| 608 | + return clone; | ||
| 609 | + }, | ||
| 610 | + | ||
| 611 | + _minBufferSize: 0 | ||
| 612 | + }); | ||
| 613 | + | ||
| 614 | + /** | ||
| 615 | + * Abstract hasher template. | ||
| 616 | + * | ||
| 617 | + * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) | ||
| 618 | + */ | ||
| 619 | + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ | ||
| 620 | + /** | ||
| 621 | + * Configuration options. | ||
| 622 | + */ | ||
| 623 | + cfg: Base.extend(), | ||
| 624 | + | ||
| 625 | + /** | ||
| 626 | + * Initializes a newly created hasher. | ||
| 627 | + * | ||
| 628 | + * @param {Object} cfg (Optional) The configuration options to use for this hash computation. | ||
| 629 | + * | ||
| 630 | + * @example | ||
| 631 | + * | ||
| 632 | + * var hasher = CryptoJS.algo.SHA256.create(); | ||
| 633 | + */ | ||
| 634 | + init: function (cfg) { | ||
| 635 | + // Apply config defaults | ||
| 636 | + this.cfg = this.cfg.extend(cfg); | ||
| 637 | + | ||
| 638 | + // Set initial values | ||
| 639 | + this.reset(); | ||
| 640 | + }, | ||
| 641 | + | ||
| 642 | + /** | ||
| 643 | + * Resets this hasher to its initial state. | ||
| 644 | + * | ||
| 645 | + * @example | ||
| 646 | + * | ||
| 647 | + * hasher.reset(); | ||
| 648 | + */ | ||
| 649 | + reset: function () { | ||
| 650 | + // Reset data buffer | ||
| 651 | + BufferedBlockAlgorithm.reset.call(this); | ||
| 652 | + | ||
| 653 | + // Perform concrete-hasher logic | ||
| 654 | + this._doReset(); | ||
| 655 | + }, | ||
| 656 | + | ||
| 657 | + /** | ||
| 658 | + * Updates this hasher with a message. | ||
| 659 | + * | ||
| 660 | + * @param {WordArray|string} messageUpdate The message to append. | ||
| 661 | + * | ||
| 662 | + * @return {Hasher} This hasher. | ||
| 663 | + * | ||
| 664 | + * @example | ||
| 665 | + * | ||
| 666 | + * hasher.update('message'); | ||
| 667 | + * hasher.update(wordArray); | ||
| 668 | + */ | ||
| 669 | + update: function (messageUpdate) { | ||
| 670 | + // Append | ||
| 671 | + this._append(messageUpdate); | ||
| 672 | + | ||
| 673 | + // Update the hash | ||
| 674 | + this._process(); | ||
| 675 | + | ||
| 676 | + // Chainable | ||
| 677 | + return this; | ||
| 678 | + }, | ||
| 679 | + | ||
| 680 | + /** | ||
| 681 | + * Finalizes the hash computation. | ||
| 682 | + * Note that the finalize operation is effectively a destructive, read-once operation. | ||
| 683 | + * | ||
| 684 | + * @param {WordArray|string} messageUpdate (Optional) A final message update. | ||
| 685 | + * | ||
| 686 | + * @return {WordArray} The hash. | ||
| 687 | + * | ||
| 688 | + * @example | ||
| 689 | + * | ||
| 690 | + * var hash = hasher.finalize(); | ||
| 691 | + * var hash = hasher.finalize('message'); | ||
| 692 | + * var hash = hasher.finalize(wordArray); | ||
| 693 | + */ | ||
| 694 | + finalize: function (messageUpdate) { | ||
| 695 | + // Final message update | ||
| 696 | + if (messageUpdate) { | ||
| 697 | + this._append(messageUpdate); | ||
| 698 | + } | ||
| 699 | + | ||
| 700 | + // Perform concrete-hasher logic | ||
| 701 | + var hash = this._doFinalize(); | ||
| 702 | + | ||
| 703 | + return hash; | ||
| 704 | + }, | ||
| 705 | + | ||
| 706 | + blockSize: 512 / 32, | ||
| 707 | + | ||
| 708 | + /** | ||
| 709 | + * Creates a shortcut function to a hasher's object interface. | ||
| 710 | + * | ||
| 711 | + * @param {Hasher} hasher The hasher to create a helper for. | ||
| 712 | + * | ||
| 713 | + * @return {Function} The shortcut function. | ||
| 714 | + * | ||
| 715 | + * @static | ||
| 716 | + * | ||
| 717 | + * @example | ||
| 718 | + * | ||
| 719 | + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); | ||
| 720 | + */ | ||
| 721 | + _createHelper: function (hasher) { | ||
| 722 | + return function (message, cfg) { | ||
| 723 | + return new hasher.init(cfg).finalize(message); | ||
| 724 | + }; | ||
| 725 | + }, | ||
| 726 | + | ||
| 727 | + /** | ||
| 728 | + * Creates a shortcut function to the HMAC's object interface. | ||
| 729 | + * | ||
| 730 | + * @param {Hasher} hasher The hasher to use in this HMAC helper. | ||
| 731 | + * | ||
| 732 | + * @return {Function} The shortcut function. | ||
| 733 | + * | ||
| 734 | + * @static | ||
| 735 | + * | ||
| 736 | + * @example | ||
| 737 | + * | ||
| 738 | + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | ||
| 739 | + */ | ||
| 740 | + _createHmacHelper: function (hasher) { | ||
| 741 | + return function (message, key) { | ||
| 742 | + return new C_algo.HMAC.init(hasher, key).finalize(message); | ||
| 743 | + }; | ||
| 744 | + } | ||
| 745 | + }); | ||
| 746 | + | ||
| 747 | + /** | ||
| 748 | + * Algorithm namespace. | ||
| 749 | + */ | ||
| 750 | + var C_algo = C.algo = {}; | ||
| 751 | + | ||
| 752 | + return C; | ||
| 753 | + }(Math)); | ||
| 754 | + | ||
| 755 | + | ||
| 756 | + return CryptoJS; | ||
| 757 | + | ||
| 758 | +})); |
miniprogram/utils/copyto/enc-base64.js
0 → 100644
| 1 | +; | ||
| 2 | +(function (root, factory) { | ||
| 3 | + if (typeof exports === "object") { | ||
| 4 | + // CommonJS | ||
| 5 | + module.exports = exports = factory(require("./core")); | ||
| 6 | + } else if (typeof define === "function" && define.amd) { | ||
| 7 | + // AMD | ||
| 8 | + define(["./core"], factory); | ||
| 9 | + } else { | ||
| 10 | + // Global (browser) | ||
| 11 | + factory(root.CryptoJS); | ||
| 12 | + } | ||
| 13 | +}(this, function (CryptoJS) { | ||
| 14 | + | ||
| 15 | + (function () { | ||
| 16 | + // Shortcuts | ||
| 17 | + var C = CryptoJS; | ||
| 18 | + var C_lib = C.lib; | ||
| 19 | + var WordArray = C_lib.WordArray; | ||
| 20 | + var C_enc = C.enc; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * Base64 encoding strategy. | ||
| 24 | + */ | ||
| 25 | + var Base64 = C_enc.Base64 = { | ||
| 26 | + /** | ||
| 27 | + * Converts a word array to a Base64 string. | ||
| 28 | + * | ||
| 29 | + * @param {WordArray} wordArray The word array. | ||
| 30 | + * | ||
| 31 | + * @return {string} The Base64 string. | ||
| 32 | + * | ||
| 33 | + * @static | ||
| 34 | + * | ||
| 35 | + * @example | ||
| 36 | + * | ||
| 37 | + * var base64String = CryptoJS.enc.Base64.stringify(wordArray); | ||
| 38 | + */ | ||
| 39 | + stringify: function (wordArray) { | ||
| 40 | + // Shortcuts | ||
| 41 | + var words = wordArray.words; | ||
| 42 | + var sigBytes = wordArray.sigBytes; | ||
| 43 | + var map = this._map; | ||
| 44 | + | ||
| 45 | + // Clamp excess bits | ||
| 46 | + wordArray.clamp(); | ||
| 47 | + | ||
| 48 | + // Convert | ||
| 49 | + var base64Chars = []; | ||
| 50 | + for (var i = 0; i < sigBytes; i += 3) { | ||
| 51 | + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
| 52 | + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; | ||
| 53 | + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; | ||
| 54 | + | ||
| 55 | + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; | ||
| 56 | + | ||
| 57 | + for (var j = 0; | ||
| 58 | + (j < 4) && (i + j * 0.75 < sigBytes); j++) { | ||
| 59 | + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + // Add padding | ||
| 64 | + var paddingChar = map.charAt(64); | ||
| 65 | + if (paddingChar) { | ||
| 66 | + while (base64Chars.length % 4) { | ||
| 67 | + base64Chars.push(paddingChar); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + return base64Chars.join(''); | ||
| 72 | + }, | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * Converts a Base64 string to a word array. | ||
| 76 | + * | ||
| 77 | + * @param {string} base64Str The Base64 string. | ||
| 78 | + * | ||
| 79 | + * @return {WordArray} The word array. | ||
| 80 | + * | ||
| 81 | + * @static | ||
| 82 | + * | ||
| 83 | + * @example | ||
| 84 | + * | ||
| 85 | + * var wordArray = CryptoJS.enc.Base64.parse(base64String); | ||
| 86 | + */ | ||
| 87 | + parse: function (base64Str) { | ||
| 88 | + // Shortcuts | ||
| 89 | + var base64StrLength = base64Str.length; | ||
| 90 | + var map = this._map; | ||
| 91 | + var reverseMap = this._reverseMap; | ||
| 92 | + | ||
| 93 | + if (!reverseMap) { | ||
| 94 | + reverseMap = this._reverseMap = []; | ||
| 95 | + for (var j = 0; j < map.length; j++) { | ||
| 96 | + reverseMap[map.charCodeAt(j)] = j; | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + // Ignore padding | ||
| 101 | + var paddingChar = map.charAt(64); | ||
| 102 | + if (paddingChar) { | ||
| 103 | + var paddingIndex = base64Str.indexOf(paddingChar); | ||
| 104 | + if (paddingIndex !== -1) { | ||
| 105 | + base64StrLength = paddingIndex; | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + // Convert | ||
| 110 | + return parseLoop(base64Str, base64StrLength, reverseMap); | ||
| 111 | + | ||
| 112 | + }, | ||
| 113 | + | ||
| 114 | + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' | ||
| 115 | + }; | ||
| 116 | + | ||
| 117 | + function parseLoop(base64Str, base64StrLength, reverseMap) { | ||
| 118 | + var words = []; | ||
| 119 | + var nBytes = 0; | ||
| 120 | + for (var i = 0; i < base64StrLength; i++) { | ||
| 121 | + if (i % 4) { | ||
| 122 | + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); | ||
| 123 | + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); | ||
| 124 | + words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); | ||
| 125 | + nBytes++; | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + return WordArray.create(words, nBytes); | ||
| 129 | + } | ||
| 130 | + }()); | ||
| 131 | + | ||
| 132 | + | ||
| 133 | + return CryptoJS.enc.Base64; | ||
| 134 | + | ||
| 135 | +})); |
miniprogram/utils/copyto/hmac-sha1.js
0 → 100644
| 1 | +/* | ||
| 2 | +CryptoJS v3.1.2 | ||
| 3 | +code.google.com/p/crypto-js | ||
| 4 | +(c) 2009-2013 by Jeff Mott. All rights reserved. | ||
| 5 | +code.google.com/p/crypto-js/wiki/License | ||
| 6 | +*/ | ||
| 7 | +var CryptoJS = CryptoJS || function (g, l) { | ||
| 8 | + var e = {}, | ||
| 9 | + d = e.lib = {}, | ||
| 10 | + m = function () {}, | ||
| 11 | + k = d.Base = { | ||
| 12 | + extend: function (a) { | ||
| 13 | + m.prototype = this; | ||
| 14 | + var c = new m; | ||
| 15 | + a && c.mixIn(a); | ||
| 16 | + c.hasOwnProperty("init") || (c.init = function () { | ||
| 17 | + c.$super.init.apply(this, arguments) | ||
| 18 | + }); | ||
| 19 | + c.init.prototype = c; | ||
| 20 | + c.$super = this; | ||
| 21 | + return c | ||
| 22 | + }, | ||
| 23 | + create: function () { | ||
| 24 | + var a = this.extend(); | ||
| 25 | + a.init.apply(a, arguments); | ||
| 26 | + return a | ||
| 27 | + }, | ||
| 28 | + init: function () {}, | ||
| 29 | + mixIn: function (a) { | ||
| 30 | + for (var c in a) a.hasOwnProperty(c) && (this[c] = a[c]); | ||
| 31 | + a.hasOwnProperty("toString") && (this.toString = a.toString) | ||
| 32 | + }, | ||
| 33 | + clone: function () { | ||
| 34 | + return this.init.prototype.extend(this) | ||
| 35 | + } | ||
| 36 | + }, | ||
| 37 | + p = d.WordArray = k.extend({ | ||
| 38 | + init: function (a, c) { | ||
| 39 | + a = this.words = a || []; | ||
| 40 | + this.sigBytes = c != l ? c : 4 * a.length | ||
| 41 | + }, | ||
| 42 | + toString: function (a) { | ||
| 43 | + return (a || n).stringify(this) | ||
| 44 | + }, | ||
| 45 | + concat: function (a) { | ||
| 46 | + var c = this.words, | ||
| 47 | + q = a.words, | ||
| 48 | + f = this.sigBytes; | ||
| 49 | + a = a.sigBytes; | ||
| 50 | + this.clamp(); | ||
| 51 | + if (f % 4) | ||
| 52 | + for (var b = 0; b < a; b++) c[f + b >>> 2] |= (q[b >>> 2] >>> 24 - 8 * (b % 4) & 255) << 24 - 8 * ((f + b) % 4); | ||
| 53 | + else if (65535 < q.length) | ||
| 54 | + for (b = 0; b < a; b += 4) c[f + b >>> 2] = q[b >>> 2]; | ||
| 55 | + else c.push.apply(c, q); | ||
| 56 | + this.sigBytes += a; | ||
| 57 | + return this | ||
| 58 | + }, | ||
| 59 | + clamp: function () { | ||
| 60 | + var a = this.words, | ||
| 61 | + c = this.sigBytes; | ||
| 62 | + a[c >>> 2] &= 4294967295 << | ||
| 63 | + 32 - 8 * (c % 4); | ||
| 64 | + a.length = g.ceil(c / 4) | ||
| 65 | + }, | ||
| 66 | + clone: function () { | ||
| 67 | + var a = k.clone.call(this); | ||
| 68 | + a.words = this.words.slice(0); | ||
| 69 | + return a | ||
| 70 | + }, | ||
| 71 | + random: function (a) { | ||
| 72 | + for (var c = [], b = 0; b < a; b += 4) c.push(4294967296 * g.random() | 0); | ||
| 73 | + return new p.init(c, a) | ||
| 74 | + } | ||
| 75 | + }), | ||
| 76 | + b = e.enc = {}, | ||
| 77 | + n = b.Hex = { | ||
| 78 | + stringify: function (a) { | ||
| 79 | + var c = a.words; | ||
| 80 | + a = a.sigBytes; | ||
| 81 | + for (var b = [], f = 0; f < a; f++) { | ||
| 82 | + var d = c[f >>> 2] >>> 24 - 8 * (f % 4) & 255; | ||
| 83 | + b.push((d >>> 4).toString(16)); | ||
| 84 | + b.push((d & 15).toString(16)) | ||
| 85 | + } | ||
| 86 | + return b.join("") | ||
| 87 | + }, | ||
| 88 | + parse: function (a) { | ||
| 89 | + for (var c = a.length, b = [], f = 0; f < c; f += 2) b[f >>> 3] |= parseInt(a.substr(f, | ||
| 90 | + 2), 16) << 24 - 4 * (f % 8); | ||
| 91 | + return new p.init(b, c / 2) | ||
| 92 | + } | ||
| 93 | + }, | ||
| 94 | + j = b.Latin1 = { | ||
| 95 | + stringify: function (a) { | ||
| 96 | + var c = a.words; | ||
| 97 | + a = a.sigBytes; | ||
| 98 | + for (var b = [], f = 0; f < a; f++) b.push(String.fromCharCode(c[f >>> 2] >>> 24 - 8 * (f % 4) & 255)); | ||
| 99 | + return b.join("") | ||
| 100 | + }, | ||
| 101 | + parse: function (a) { | ||
| 102 | + for (var c = a.length, b = [], f = 0; f < c; f++) b[f >>> 2] |= (a.charCodeAt(f) & 255) << 24 - 8 * (f % 4); | ||
| 103 | + return new p.init(b, c) | ||
| 104 | + } | ||
| 105 | + }, | ||
| 106 | + h = b.Utf8 = { | ||
| 107 | + stringify: function (a) { | ||
| 108 | + try { | ||
| 109 | + return decodeURIComponent(escape(j.stringify(a))) | ||
| 110 | + } catch (c) { | ||
| 111 | + throw Error("Malformed UTF-8 data"); | ||
| 112 | + } | ||
| 113 | + }, | ||
| 114 | + parse: function (a) { | ||
| 115 | + return j.parse(unescape(encodeURIComponent(a))) | ||
| 116 | + } | ||
| 117 | + }, | ||
| 118 | + r = d.BufferedBlockAlgorithm = k.extend({ | ||
| 119 | + reset: function () { | ||
| 120 | + this._data = new p.init; | ||
| 121 | + this._nDataBytes = 0 | ||
| 122 | + }, | ||
| 123 | + _append: function (a) { | ||
| 124 | + "string" == typeof a && (a = h.parse(a)); | ||
| 125 | + this._data.concat(a); | ||
| 126 | + this._nDataBytes += a.sigBytes | ||
| 127 | + }, | ||
| 128 | + _process: function (a) { | ||
| 129 | + var c = this._data, | ||
| 130 | + b = c.words, | ||
| 131 | + f = c.sigBytes, | ||
| 132 | + d = this.blockSize, | ||
| 133 | + e = f / (4 * d), | ||
| 134 | + e = a ? g.ceil(e) : g.max((e | 0) - this._minBufferSize, 0); | ||
| 135 | + a = e * d; | ||
| 136 | + f = g.min(4 * a, f); | ||
| 137 | + if (a) { | ||
| 138 | + for (var k = 0; k < a; k += d) this._doProcessBlock(b, k); | ||
| 139 | + k = b.splice(0, a); | ||
| 140 | + c.sigBytes -= f | ||
| 141 | + } | ||
| 142 | + return new p.init(k, f) | ||
| 143 | + }, | ||
| 144 | + clone: function () { | ||
| 145 | + var a = k.clone.call(this); | ||
| 146 | + a._data = this._data.clone(); | ||
| 147 | + return a | ||
| 148 | + }, | ||
| 149 | + _minBufferSize: 0 | ||
| 150 | + }); | ||
| 151 | + d.Hasher = r.extend({ | ||
| 152 | + cfg: k.extend(), | ||
| 153 | + init: function (a) { | ||
| 154 | + this.cfg = this.cfg.extend(a); | ||
| 155 | + this.reset() | ||
| 156 | + }, | ||
| 157 | + reset: function () { | ||
| 158 | + r.reset.call(this); | ||
| 159 | + this._doReset() | ||
| 160 | + }, | ||
| 161 | + update: function (a) { | ||
| 162 | + this._append(a); | ||
| 163 | + this._process(); | ||
| 164 | + return this | ||
| 165 | + }, | ||
| 166 | + finalize: function (a) { | ||
| 167 | + a && this._append(a); | ||
| 168 | + return this._doFinalize() | ||
| 169 | + }, | ||
| 170 | + blockSize: 16, | ||
| 171 | + _createHelper: function (a) { | ||
| 172 | + return function (b, d) { | ||
| 173 | + return (new a.init(d)).finalize(b) | ||
| 174 | + } | ||
| 175 | + }, | ||
| 176 | + _createHmacHelper: function (a) { | ||
| 177 | + return function (b, d) { | ||
| 178 | + return (new s.HMAC.init(a, | ||
| 179 | + d)).finalize(b) | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + }); | ||
| 183 | + var s = e.algo = {}; | ||
| 184 | + return e | ||
| 185 | +}(Math); | ||
| 186 | +(function () { | ||
| 187 | + var g = CryptoJS, | ||
| 188 | + l = g.lib, | ||
| 189 | + e = l.WordArray, | ||
| 190 | + d = l.Hasher, | ||
| 191 | + m = [], | ||
| 192 | + l = g.algo.SHA1 = d.extend({ | ||
| 193 | + _doReset: function () { | ||
| 194 | + this._hash = new e.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) | ||
| 195 | + }, | ||
| 196 | + _doProcessBlock: function (d, e) { | ||
| 197 | + for (var b = this._hash.words, n = b[0], j = b[1], h = b[2], g = b[3], l = b[4], a = 0; 80 > a; a++) { | ||
| 198 | + if (16 > a) m[a] = d[e + a] | 0; | ||
| 199 | + else { | ||
| 200 | + var c = m[a - 3] ^ m[a - 8] ^ m[a - 14] ^ m[a - 16]; | ||
| 201 | + m[a] = c << 1 | c >>> 31 | ||
| 202 | + } | ||
| 203 | + c = (n << 5 | n >>> 27) + l + m[a]; | ||
| 204 | + c = 20 > a ? c + ((j & h | ~j & g) + 1518500249) : 40 > a ? c + ((j ^ h ^ g) + 1859775393) : 60 > a ? c + ((j & h | j & g | h & g) - 1894007588) : c + ((j ^ h ^ | ||
| 205 | + g) - 899497514); | ||
| 206 | + l = g; | ||
| 207 | + g = h; | ||
| 208 | + h = j << 30 | j >>> 2; | ||
| 209 | + j = n; | ||
| 210 | + n = c | ||
| 211 | + } | ||
| 212 | + b[0] = b[0] + n | 0; | ||
| 213 | + b[1] = b[1] + j | 0; | ||
| 214 | + b[2] = b[2] + h | 0; | ||
| 215 | + b[3] = b[3] + g | 0; | ||
| 216 | + b[4] = b[4] + l | 0 | ||
| 217 | + }, | ||
| 218 | + _doFinalize: function () { | ||
| 219 | + var d = this._data, | ||
| 220 | + e = d.words, | ||
| 221 | + b = 8 * this._nDataBytes, | ||
| 222 | + g = 8 * d.sigBytes; | ||
| 223 | + e[g >>> 5] |= 128 << 24 - g % 32; | ||
| 224 | + e[(g + 64 >>> 9 << 4) + 14] = Math.floor(b / 4294967296); | ||
| 225 | + e[(g + 64 >>> 9 << 4) + 15] = b; | ||
| 226 | + d.sigBytes = 4 * e.length; | ||
| 227 | + this._process(); | ||
| 228 | + return this._hash | ||
| 229 | + }, | ||
| 230 | + clone: function () { | ||
| 231 | + var e = d.clone.call(this); | ||
| 232 | + e._hash = this._hash.clone(); | ||
| 233 | + return e | ||
| 234 | + } | ||
| 235 | + }); | ||
| 236 | + g.SHA1 = d._createHelper(l); | ||
| 237 | + g.HmacSHA1 = d._createHmacHelper(l) | ||
| 238 | +})(); | ||
| 239 | +(function () { | ||
| 240 | + var g = CryptoJS, | ||
| 241 | + l = g.enc.Utf8; | ||
| 242 | + g.algo.HMAC = g.lib.Base.extend({ | ||
| 243 | + init: function (e, d) { | ||
| 244 | + e = this._hasher = new e.init; | ||
| 245 | + "string" == typeof d && (d = l.parse(d)); | ||
| 246 | + var g = e.blockSize, | ||
| 247 | + k = 4 * g; | ||
| 248 | + d.sigBytes > k && (d = e.finalize(d)); | ||
| 249 | + d.clamp(); | ||
| 250 | + for (var p = this._oKey = d.clone(), b = this._iKey = d.clone(), n = p.words, j = b.words, h = 0; h < g; h++) n[h] ^= 1549556828, j[h] ^= 909522486; | ||
| 251 | + p.sigBytes = b.sigBytes = k; | ||
| 252 | + this.reset() | ||
| 253 | + }, | ||
| 254 | + reset: function () { | ||
| 255 | + var e = this._hasher; | ||
| 256 | + e.reset(); | ||
| 257 | + e.update(this._iKey) | ||
| 258 | + }, | ||
| 259 | + update: function (e) { | ||
| 260 | + this._hasher.update(e); | ||
| 261 | + return this | ||
| 262 | + }, | ||
| 263 | + finalize: function (e) { | ||
| 264 | + var d = | ||
| 265 | + this._hasher; | ||
| 266 | + e = d.finalize(e); | ||
| 267 | + d.reset(); | ||
| 268 | + return d.finalize(this._oKey.clone().concat(e)) | ||
| 269 | + } | ||
| 270 | + }) | ||
| 271 | +})(); | ||
| 272 | +module.exports = CryptoJS |
miniprogram/utils/ieee754.js
0 → 100644
| 1 | +exports.read = function (buffer, offset, isLE, mLen, nBytes) { | ||
| 2 | + var e, m | ||
| 3 | + var eLen = (nBytes * 8) - mLen - 1 | ||
| 4 | + var eMax = (1 << eLen) - 1 | ||
| 5 | + var eBias = eMax >> 1 | ||
| 6 | + var nBits = -7 | ||
| 7 | + var i = isLE ? (nBytes - 1) : 0 | ||
| 8 | + var d = isLE ? -1 : 1 | ||
| 9 | + var s = buffer[offset + i] | ||
| 10 | + | ||
| 11 | + i += d | ||
| 12 | + | ||
| 13 | + e = s & ((1 << (-nBits)) - 1) | ||
| 14 | + s >>= (-nBits) | ||
| 15 | + nBits += eLen | ||
| 16 | + for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} | ||
| 17 | + | ||
| 18 | + m = e & ((1 << (-nBits)) - 1) | ||
| 19 | + e >>= (-nBits) | ||
| 20 | + nBits += mLen | ||
| 21 | + for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} | ||
| 22 | + | ||
| 23 | + if (e === 0) { | ||
| 24 | + e = 1 - eBias | ||
| 25 | + } else if (e === eMax) { | ||
| 26 | + return m ? NaN : ((s ? -1 : 1) * Infinity) | ||
| 27 | + } else { | ||
| 28 | + m = m + Math.pow(2, mLen) | ||
| 29 | + e = e - eBias | ||
| 30 | + } | ||
| 31 | + return (s ? -1 : 1) * m * Math.pow(2, e - mLen) | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { | ||
| 35 | + var e, m, c | ||
| 36 | + var eLen = (nBytes * 8) - mLen - 1 | ||
| 37 | + var eMax = (1 << eLen) - 1 | ||
| 38 | + var eBias = eMax >> 1 | ||
| 39 | + var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) | ||
| 40 | + var i = isLE ? 0 : (nBytes - 1) | ||
| 41 | + var d = isLE ? 1 : -1 | ||
| 42 | + var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 | ||
| 43 | + | ||
| 44 | + value = Math.abs(value) | ||
| 45 | + | ||
| 46 | + if (isNaN(value) || value === Infinity) { | ||
| 47 | + m = isNaN(value) ? 1 : 0 | ||
| 48 | + e = eMax | ||
| 49 | + } else { | ||
| 50 | + e = Math.floor(Math.log(value) / Math.LN2) | ||
| 51 | + if (value * (c = Math.pow(2, -e)) < 1) { | ||
| 52 | + e-- | ||
| 53 | + c *= 2 | ||
| 54 | + } | ||
| 55 | + if (e + eBias >= 1) { | ||
| 56 | + value += rt / c | ||
| 57 | + } else { | ||
| 58 | + value += rt * Math.pow(2, 1 - eBias) | ||
| 59 | + } | ||
| 60 | + if (value * c >= 2) { | ||
| 61 | + e++ | ||
| 62 | + c /= 2 | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + if (e + eBias >= eMax) { | ||
| 66 | + m = 0 | ||
| 67 | + e = eMax | ||
| 68 | + } else if (e + eBias >= 1) { | ||
| 69 | + m = ((value * c) - 1) * Math.pow(2, mLen) | ||
| 70 | + e = e + eBias | ||
| 71 | + } else { | ||
| 72 | + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) | ||
| 73 | + e = 0 | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} | ||
| 78 | + | ||
| 79 | + e = (e << mLen) | m | ||
| 80 | + eLen += mLen | ||
| 81 | + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} | ||
| 82 | + | ||
| 83 | + buffer[offset + i - d] |= s * 128 | ||
| 84 | +} |
miniprogram/utils/qiniuUploader.js
0 → 100644
| 1 | +(function () { | ||
| 2 | + var config = { | ||
| 3 | + qiniuRegion: '', | ||
| 4 | + qiniuImageURLPrefix: '', | ||
| 5 | + qiniuUploadToken: '', | ||
| 6 | + qiniuUploadTokenURL: '', | ||
| 7 | + qiniuUploadTokenFunction: null, | ||
| 8 | + qiniuShouldUseQiniuFileName: false | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + module.exports = { | ||
| 12 | + init: init, | ||
| 13 | + upload: upload, | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + // 在整个程序生命周期中,只需要 init 一次即可 | ||
| 17 | + // 如果需要变更参数,再调用 init 即可 | ||
| 18 | + function init(options) { | ||
| 19 | + config = { | ||
| 20 | + qiniuRegion: '', | ||
| 21 | + qiniuImageURLPrefix: '', | ||
| 22 | + qiniuUploadToken: '', | ||
| 23 | + qiniuUploadTokenURL: '', | ||
| 24 | + qiniuUploadTokenFunction: null, | ||
| 25 | + qiniuShouldUseQiniuFileName: false | ||
| 26 | + }; | ||
| 27 | + updateConfigWithOptions(options); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + function updateConfigWithOptions(options) { | ||
| 31 | + if (options.region) { | ||
| 32 | + config.qiniuRegion = options.region; | ||
| 33 | + } else { | ||
| 34 | + console.error('qiniu uploader need your bucket region'); | ||
| 35 | + } | ||
| 36 | + if (options.uptoken) { | ||
| 37 | + config.qiniuUploadToken = options.uptoken; | ||
| 38 | + } else if (options.uptokenURL) { | ||
| 39 | + config.qiniuUploadTokenURL = options.uptokenURL; | ||
| 40 | + } else if (options.uptokenFunc) { | ||
| 41 | + config.qiniuUploadTokenFunction = options.uptokenFunc; | ||
| 42 | + } | ||
| 43 | + if (options.domain) { | ||
| 44 | + config.qiniuImageURLPrefix = options.domain; | ||
| 45 | + } | ||
| 46 | + config.qiniuShouldUseQiniuFileName = options.shouldUseQiniuFileName | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + function upload(filePath, success, fail, options, progress, cancelTask, before, complete) { | ||
| 50 | + if (null == filePath) { | ||
| 51 | + console.error('qiniu uploader need filePath to upload'); | ||
| 52 | + return; | ||
| 53 | + } | ||
| 54 | + if (options) { | ||
| 55 | + updateConfigWithOptions(options); | ||
| 56 | + } | ||
| 57 | + if (config.qiniuUploadToken) { | ||
| 58 | + doUpload(filePath, success, fail, options, progress, cancelTask, before, complete); | ||
| 59 | + } else if (config.qiniuUploadTokenURL) { | ||
| 60 | + getQiniuToken(function () { | ||
| 61 | + doUpload(filePath, success, fail, options, progress, cancelTask, before, complete); | ||
| 62 | + }); | ||
| 63 | + } else if (config.qiniuUploadTokenFunction) { | ||
| 64 | + config.qiniuUploadToken = config.qiniuUploadTokenFunction(); | ||
| 65 | + if (null == config.qiniuUploadToken && config.qiniuUploadToken.length > 0) { | ||
| 66 | + console.error('qiniu UploadTokenFunction result is null, please check the return value'); | ||
| 67 | + return | ||
| 68 | + } | ||
| 69 | + doUpload(filePath, success, fail, options, progress, cancelTask, before, complete); | ||
| 70 | + } else { | ||
| 71 | + console.error('qiniu uploader need one of [uptoken, uptokenURL, uptokenFunc]'); | ||
| 72 | + return; | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + function doUpload(filePath, success, fail, options, progress, cancelTask, before, complete) { | ||
| 77 | + if (null == config.qiniuUploadToken && config.qiniuUploadToken.length > 0) { | ||
| 78 | + console.error('qiniu UploadToken is null, please check the init config or networking'); | ||
| 79 | + return | ||
| 80 | + } | ||
| 81 | + var url = uploadURLFromRegionCode(config.qiniuRegion); | ||
| 82 | + console.log('filePathfilePathfilePath', filePath); | ||
| 83 | + var fileName = filePath[0].split('//')[1]; | ||
| 84 | + if (options && options.key) { | ||
| 85 | + fileName = options.key; | ||
| 86 | + } | ||
| 87 | + var formData = { | ||
| 88 | + 'token': config.qiniuUploadToken | ||
| 89 | + }; | ||
| 90 | + if (!config.qiniuShouldUseQiniuFileName) { | ||
| 91 | + formData['key'] = fileName | ||
| 92 | + } | ||
| 93 | + before && before(); | ||
| 94 | + var uploadTask = wx.uploadFile({ | ||
| 95 | + url: url, | ||
| 96 | + filePath: filePath, | ||
| 97 | + name: 'file', | ||
| 98 | + formData: formData, | ||
| 99 | + success: function (res) { | ||
| 100 | + var dataString = res.data | ||
| 101 | + // // this if case is a compatibility with wechat server returned a charcode, but was fixed | ||
| 102 | + // if(res.data.hasOwnProperty('type') && res.data.type === 'Buffer'){ | ||
| 103 | + // dataString = String.fromCharCode.apply(null, res.data.data) | ||
| 104 | + // } | ||
| 105 | + try { | ||
| 106 | + var dataObject = JSON.parse(dataString); | ||
| 107 | + //do something | ||
| 108 | + var fileUrl = config.qiniuImageURLPrefix + '/' + dataObject.key; | ||
| 109 | + dataObject.fileUrl = fileUrl | ||
| 110 | + dataObject.imageURL = fileUrl; | ||
| 111 | + // console.log(dataObject); | ||
| 112 | + if (success) { | ||
| 113 | + success(dataObject); | ||
| 114 | + } | ||
| 115 | + } catch (e) { | ||
| 116 | + console.log('parse JSON failed, origin String is: ' + dataString) | ||
| 117 | + if (fail) { | ||
| 118 | + fail(e); | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + }, | ||
| 122 | + fail: function (error) { | ||
| 123 | + console.error(error); | ||
| 124 | + if (fail) { | ||
| 125 | + fail(error); | ||
| 126 | + } | ||
| 127 | + }, | ||
| 128 | + complete: function (err) { | ||
| 129 | + complete && complete(err); | ||
| 130 | + } | ||
| 131 | + }) | ||
| 132 | + | ||
| 133 | + uploadTask.onProgressUpdate((res) => { | ||
| 134 | + progress && progress(res) | ||
| 135 | + }) | ||
| 136 | + | ||
| 137 | + cancelTask && cancelTask(() => { | ||
| 138 | + uploadTask.abort() | ||
| 139 | + }) | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + function getQiniuToken(callback) { | ||
| 143 | + console.log('urlurl', config.qiniuUploadTokenURL); | ||
| 144 | + wx.request({ | ||
| 145 | + url: config.qiniuUploadTokenURL, | ||
| 146 | + header: { | ||
| 147 | + 'Content-Type': "application/json", | ||
| 148 | + // 'Cookie': 'vertx-web.session=' + wx.getStorageSync("sessionId") | ||
| 149 | + }, | ||
| 150 | + success: function (res) { | ||
| 151 | + var token = res.data.message; | ||
| 152 | + if (token && token.length > 0) { | ||
| 153 | + config.qiniuUploadToken = token; | ||
| 154 | + if (callback) { | ||
| 155 | + callback(); | ||
| 156 | + } | ||
| 157 | + } else { | ||
| 158 | + console.error('qiniuUploader cannot get your token, please check the uptokenURL or server') | ||
| 159 | + } | ||
| 160 | + }, | ||
| 161 | + fail: function (error) { | ||
| 162 | + console.error('qiniu UploadToken is null, please check the init config or networking: ' + error); | ||
| 163 | + } | ||
| 164 | + }) | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + function uploadURLFromRegionCode(code) { | ||
| 168 | + var uploadURL = null; | ||
| 169 | + switch (code) { | ||
| 170 | + case 'ECN': | ||
| 171 | + uploadURL = 'https://up.qiniup.com'; | ||
| 172 | + break; | ||
| 173 | + case 'NCN': | ||
| 174 | + uploadURL = 'https://up-z1.qiniup.com'; | ||
| 175 | + break; | ||
| 176 | + case 'z2': | ||
| 177 | + uploadURL = 'https://up-z0.qiniup.com'; | ||
| 178 | + break; | ||
| 179 | + case 'NA': | ||
| 180 | + uploadURL = 'https://up-na0.qiniup.com'; | ||
| 181 | + break; | ||
| 182 | + case 'ASG': | ||
| 183 | + uploadURL = 'https://up-as0.qiniup.com'; | ||
| 184 | + break; | ||
| 185 | + default: | ||
| 186 | + console.error('please make the region is with one of [ECN, SCN, NCN, NA, ASG]'); | ||
| 187 | + } | ||
| 188 | + return uploadURL; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | +})(); |
| 1 | var uri = require('uri.js') | 1 | var uri = require('uri.js') |
| 2 | +const Buffer = require('./buffer.js'); | ||
| 3 | +const CryptoJS = require('./copyto/hmac-sha1.js'); | ||
| 4 | +const base64 = require('./copyto/enc-base64.js'); | ||
| 5 | +import qiniuUploader from "./qiniuUploader"; | ||
| 2 | 6 | ||
| 3 | function formatTime(date, type, connect) { | 7 | function formatTime(date, type, connect) { |
| 4 | var year = date.getFullYear() | 8 | var year = date.getFullYear() |
| @@ -182,7 +186,75 @@ function objCompare (obj1, obj2,key){ | @@ -182,7 +186,75 @@ function objCompare (obj1, obj2,key){ | ||
| 182 | // 判断是数组还是对象 返回 object 或者 array | 186 | // 判断是数组还是对象 返回 object 或者 array |
| 183 | function getType(variable) { | 187 | function getType(variable) { |
| 184 | return ({}).toString.call(variable).match(/\s([a-zA-Z]+)/)[1].toLowerCase(); | 188 | return ({}).toString.call(variable).match(/\s([a-zA-Z]+)/)[1].toLowerCase(); |
| 185 | -} | 189 | +} |
| 190 | +// 上传图片 | ||
| 191 | +function uploadFile(imgArr, token,type){ | ||
| 192 | + let path = imgArr.split('//')[1] | ||
| 193 | + let promisevariable = new Promise(function (resolve, reject) { | ||
| 194 | + qiniuUploader.upload( | ||
| 195 | + imgArr, //上传的图片 | ||
| 196 | + (res) => { //回调 success | ||
| 197 | + console.log(res, '七牛云返回') | ||
| 198 | + resolve(res.imageURL) | ||
| 199 | + }, (error) => { //回调 fail | ||
| 200 | + reject('error'); | ||
| 201 | + }, | ||
| 202 | + { // 参数设置 地区代码 token domain 和直传的链接 注意七牛四个不同地域的链接不一样,我使用的是华南地区 | ||
| 203 | + uptokenURL: token, | ||
| 204 | + uploadURL: 'http://nosqn.colorcun.com', | ||
| 205 | + region: 'ECN', //服务器区域号 | ||
| 206 | + domain: 'http://nosqn.colorcun.com',//七牛云域名 | ||
| 207 | + key: `pinglun/${type}/${path}`, // 上传到七牛云图片就是这路径 | ||
| 208 | + uptoken: token, | ||
| 209 | + uptokeFunc:'', | ||
| 210 | + }) | ||
| 211 | + }) | ||
| 212 | + return promisevariable; | ||
| 213 | +} | ||
| 214 | +function base64ToUrlSafe(v) { | ||
| 215 | + return v.replace(/\//g, '_').replace(/\+/g, '-'); | ||
| 216 | +}; | ||
| 217 | +// 删除 | ||
| 218 | +function deletelUpload(filename,token,cb) { | ||
| 219 | + var secretkey = 'oZMMVN6phk49lG0J1xwmi1Ju0ETT15EnAEWcU9Cs'; //你的sk | ||
| 220 | + var accessKey = 'uva-aaonM8dukeR6phc9yuPBrOXk9brrNW_PxLD7'; | ||
| 221 | + var bucket = 'colorcun-attr' //你的空间名 | ||
| 222 | + var cdn = 'http://nosqn.colorcun.com' //CDN 测试域名 | ||
| 223 | + var str = bucket + ':' + filename.split( cdn + '/')[1]; | ||
| 224 | + var encoded = Buffer.from(str).toString('base64'); //字符串64编码 | ||
| 225 | + var encodedEntryURI = base64ToUrlSafe(encoded); //安全编码就是替换掉一些符号看 | ||
| 226 | + var signingStr = '/delete/' + encodedEntryURI + '\n' | ||
| 227 | + var sign = CryptoJS.HmacSHA1(signingStr, secretkey); //HmacSHA1签名 | ||
| 228 | + var cod = base64.stringify(sign); //HmacSHA1的64编码 | ||
| 229 | + var encodedSign = base64ToUrlSafe(cod); | ||
| 230 | + // 拼接accessToken | ||
| 231 | + var accessToken = accessKey + ":" + encodedSign | ||
| 232 | + wx.request({ | ||
| 233 | + url: "https://rs.qiniuapi.com/delete/" + encodedEntryURI, | ||
| 234 | + method: "POST", | ||
| 235 | + header: { | ||
| 236 | + "Content-Type": "application/x-www-form-urlencoded", | ||
| 237 | + "Authorization": 'QBox '+accessToken | ||
| 238 | + }, | ||
| 239 | + success: function (res) { | ||
| 240 | + wx.showToast({ | ||
| 241 | + title: '删除成功!', | ||
| 242 | + icon: 'none', | ||
| 243 | + duration: 500 | ||
| 244 | + }) | ||
| 245 | + return typeof cb == "function" && cb(res.data) //更具返回数据判断 | ||
| 246 | + }, | ||
| 247 | + fail: function (fail) { | ||
| 248 | + console.log('删除失败',fail); | ||
| 249 | + wx.showToast({ | ||
| 250 | + title: '删除失败', | ||
| 251 | + icon: 'none', | ||
| 252 | + duration: 500 | ||
| 253 | + }) | ||
| 254 | + return typeof cb == "function" && cb(false) | ||
| 255 | + } | ||
| 256 | + }) | ||
| 257 | +}; | ||
| 186 | module.exports = { | 258 | module.exports = { |
| 187 | formatTime: formatTime, | 259 | formatTime: formatTime, |
| 188 | unixtoTime: unixtoTime, | 260 | unixtoTime: unixtoTime, |
| @@ -192,6 +264,8 @@ module.exports = { | @@ -192,6 +264,8 @@ module.exports = { | ||
| 192 | objCompare, | 264 | objCompare, |
| 193 | getType, | 265 | getType, |
| 194 | imageZoomHeightUtil, | 266 | imageZoomHeightUtil, |
| 267 | + uploadFile, | ||
| 268 | + deletelUpload, | ||
| 195 | cgi: function (act) { | 269 | cgi: function (act) { |
| 196 | return uri.HOST__LINE + act //正式 | 270 | return uri.HOST__LINE + act //正式 |
| 197 | //return uri.HOST__TEST+act //测试 | 271 | //return uri.HOST__TEST+act //测试 |
-
Please register or login to post a comment