nv-facutil-bufa
v1.0.3
Published
nv-facutil-bufa ======================= - a buffer support append |prepend | insert before index | insert after index | replace from index to index | remove from index to index | splice
Downloads
4
Readme
nv-facutil-bufa
- a buffer support append |prepend | insert before index | insert after index | replace from index to index | remove from index to index | splice
install
- npm install nv-facutil-bufa
splitted
usage
const { creat, Buf } = require("nv-facutil-bufa");
example
apend
apend(ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) -> ei
var buf = creat(10)
/*
> buf
Buf {
ei: 0,
u8a: Uint8Array(10) [
0, 0, 0, 0, 0,
0, 0, 0, 0, 0
],
segsz: 10
}
> buf.apend([1,2,3,4,5])
5
> buf
Buf {
ei: 5,
u8a: Uint8Array(10) [
1, 2, 3, 4, 5,
0, 0, 0, 0, 0
],
segsz: 10
}
> buf.apend([1,2,3,4,5,6,7])
12
> buf
Buf {
ei: 12,
u8a: Uint8Array(20) [
1, 2, 3, 4, 5, 1, 2,
3, 4, 5, 6, 7, 0, 0,
0, 0, 0, 0, 0, 0
],
segsz: 10
}
> buf.cp_data()
Uint8Array(12) [
1, 2, 3, 4, 5,
1, 2, 3, 4, 5,
6, 7
]
>
*/
ppend
ppend(ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) -> ei
> buf.ppend([1,2,3,4,5])
5
> buf
Buf {
ei: 5,
u8a: Uint8Array(10) [
1, 2, 3, 4, 5,
0, 0, 0, 0, 0
],
segsz: 10
}
> buf.ppend([1,2,3,4,5,6])
11
> buf
Buf {
ei: 11,
u8a: Uint8Array(20) [
1, 2, 3, 4, 5, 6, 1,
2, 3, 4, 5, 0, 0, 0,
0, 0, 0, 0, 0, 0
],
segsz: 10
}
> buf.cp_data()
Uint8Array(11) [
1, 2, 3, 4, 5,
6, 1, 2, 3, 4,
5
]
>
> buf.data_
Uint8Array(11) [
1, 2, 3, 4, 5,
6, 1, 2, 3, 4,
5
]
>
insert before
.insert_bfr(Index, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) -> ei
var buf = creat(10)
> buf.apend([0,1,2,3,4,5])
6
> buf
Buf {
ei: 6,
u8a: Uint8Array(10) [
0, 1, 2, 3, 4,
5, 0, 0, 0, 0
],
segsz: 10
}
> buf.insert_bfr(2,[11,22,33])
9
> buf
Buf {
ei: 9,
u8a: Uint8Array(10) [
0, 1, 11, 22, 33,
2, 3, 4, 5, 0
],
segsz: 10
}
> buf.insert_bfr(2,[21,22,23,24,25,26,27,28])
17
> buf
Buf {
ei: 17,
u8a: Uint8Array(20) [
0, 1, 21, 22, 23, 24, 25,
26, 27, 28, 11, 22, 33, 2,
3, 4, 5, 0, 0, 0
],
segsz: 10
}
> buf.data_
Uint8Array(17) [
0, 1, 21, 22, 23, 24, 25,
26, 27, 28, 11, 22, 33, 2,
3, 4, 5
]
> buf.cp_data()
Uint8Array(17) [
0, 1, 21, 22, 23, 24, 25,
26, 27, 28, 11, 22, 33, 2,
3, 4, 5
]
>
insert after
.insert_aft(Index, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) -> ei
same as .insert_bfr(Index+1, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf)
replace
.rplc_rng(si,ei, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) -> ei
//same as .splice(si, ei-si, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf)
> var u8a = new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11])
> var buf = creat(10)
> buf.apend(u8a)
12
> buf
Buf {
ei: 12,
u8a: Uint8Array(20) [
0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 0, 0,
0, 0, 0, 0, 0, 0
],
segsz: 10
}
> buf.rplc_rng(3,9,[255,255,255])
9
> buf
Buf {
ei: 9,
u8a: Uint8Array(20) [
0, 1, 2, 255, 255, 255, 9,
10, 11, 9, 10, 11, 0, 0,
0, 0, 0, 0, 0, 0
],
segsz: 10
}
> buf.data_
Uint8Array(9) [
0, 1, 2, 255, 255,
255, 9, 10, 11
]
> buf.cp_data()
Uint8Array(9) [
0, 1, 2, 255, 255,
255, 9, 10, 11
]
>
remove
.rm_rng(si,ei) -> ei;
> var buf = creat(10)
>
> buf.apend([0,1,2,3,4,5,6,7])
8
> buf
Buf {
ei: 8,
u8a: Uint8Array(10) [
0, 1, 2, 3, 4,
5, 6, 7, 0, 0
],
segsz: 10
}
> buf.rm_rng(2,4)
6
> buf
Buf {
ei: 6,
u8a: Uint8Array(10) [
0, 1, 4, 5, 6,
7, 6, 7, 0, 0
],
segsz: 10
}
> buf.data_
Uint8Array(6) [ 0, 1, 4, 5, 6, 7 ]
>
> buf.cp_data()
Uint8Array(6) [ 0, 1, 4, 5, 6, 7 ]
>
>
splice
.splice(Index,remove_count, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) ->ei
> var buf = creat(10)
> buf.apend([0,1,2,3,4,5,6,7,8,9,10,11])
12
> buf
Buf {
ei: 12,
u8a: Uint8Array(20) [
0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 0, 0,
0, 0, 0, 0, 0, 0
],
segsz: 10
}
> buf.splice(2,3,[11,22,33,44])
13
> buf
Buf {
ei: 13,
u8a: Uint8Array(20) [
0, 1, 11, 22, 33, 44, 5,
6, 7, 8, 9, 10, 11, 0,
0, 0, 0, 0, 0, 0
],
segsz: 10
}
> buf.splice(2,0,[11,22,33,44])
17
> buf
Buf {
ei: 17,
u8a: Uint8Array(20) [
0, 1, 11, 22, 33, 44, 11,
22, 33, 44, 5, 6, 7, 8,
9, 10, 11, 0, 0, 0
],
segsz: 10
}
> buf.splice(2,4,[])
13
> buf
Buf {
ei: 13,
u8a: Uint8Array(20) [
0, 1, 11, 22, 33, 44, 5,
6, 7, 8, 9, 10, 11, 8,
9, 10, 11, 0, 0, 0
],
segsz: 10
}
>
METHODS
//methods:
.apend(ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) ->ei
.ppend(ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) ->ei
.insert_bfr(Index, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) ->ei
.insert_aft(Index, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) ->ei
.rplc_rng(si,ei, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) ->ei
.rm_rng(si,ei) ->ei
.splice(Index,remove_count, ArrayBuffer|Uint8Array|Array<uint8_t>|Buf) ->ei
.cp_data() -> Uint8Array
.clone() -> Buf
//getters
.data_ (subarray)
.ei
.segsz
APIS
creat(segment_size=10)->Buf
LICENSE
- ISC