Created
          September 12, 2013 02:48 
        
      - 
      
- 
        Save smallnewer/6532574 to your computer and use it in GitHub Desktop. 
    链接两个buffer,类似数组的concat操作。实际操作的是两个Uint8Array。
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /** | |
| * Appends two ArrayBuffers into a new one. | |
| * | |
| * @param {ArrayBuffer} buffer1 The first buffer. | |
| * @param {ArrayBuffer} buffer2 The second buffer. | |
| */ | |
| function appendBuffer(buffer1, buffer2) { | |
| var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength); | |
| tmp.set( new Uint8Array(buffer1), 0); | |
| tmp.set( new Uint8Array(buffer2), buffer1.byteLength); | |
| return tmp; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // 创建一个新的全局对象,保存buffer | |
| var buffer = new Uint8Array(); | |
| // 将新的buffer插入到之前的buffer上 | |
| buffer = appendBuffer(buffer,newbuf); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment