|
1 | 1 | /* global Buffer */ |
2 | | -"use strict"; |
| 2 | +import { inspect } from "util"; |
| 3 | +export const showImpl = inspect; |
3 | 4 |
|
4 | | -exports.showImpl = require("util").inspect; |
5 | | - |
6 | | -exports.eqImpl = function (a) { |
7 | | - return function (b) { |
| 5 | +export function eqImpl(a) { |
| 6 | + return b => { |
8 | 7 | return a.equals(b); |
9 | 8 | }; |
10 | | -}; |
| 9 | +} |
11 | 10 |
|
12 | | -exports.compareImpl = function (a) { |
13 | | - return function (b) { |
| 11 | +export function compareImpl(a) { |
| 12 | + return b => { |
14 | 13 | return a.compare(b); |
15 | 14 | }; |
16 | | -}; |
| 15 | +} |
17 | 16 |
|
18 | | -exports.create = function (size) { |
| 17 | +export function create(size) { |
19 | 18 | return Buffer.alloc(size); |
20 | | -}; |
| 19 | +} |
21 | 20 |
|
22 | | -exports.fromArray = function (octets) { |
| 21 | +export function fromArray(octets) { |
23 | 22 | return Buffer.from(octets); |
24 | | -}; |
| 23 | +} |
25 | 24 |
|
26 | | -exports.size = function (buff) { |
| 25 | +export function size(buff) { |
27 | 26 | return buff.length; |
28 | | -}; |
| 27 | +} |
29 | 28 |
|
30 | | -exports.toArray = function (buff) { |
| 29 | +export function toArray(buff) { |
31 | 30 | var json = buff.toJSON(); |
32 | 31 | return json.data || json; |
33 | | -}; |
| 32 | +} |
34 | 33 |
|
35 | | -exports.toArrayBuffer = function (buff) { |
| 34 | +export function toArrayBuffer(buff) { |
36 | 35 | return buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength); |
37 | | -}; |
| 36 | +} |
38 | 37 |
|
39 | | -exports.fromArrayBuffer = function (ab) { |
| 38 | +export function fromArrayBuffer(ab) { |
40 | 39 | return Buffer.from(ab); |
41 | | -}; |
| 40 | +} |
42 | 41 |
|
43 | | -exports.fromStringImpl = function (str) { |
44 | | - return function (encoding) { |
| 42 | +export function fromStringImpl(str) { |
| 43 | + return encoding => { |
45 | 44 | return Buffer.from(str, encoding); |
46 | 45 | }; |
47 | | -}; |
| 46 | +} |
48 | 47 |
|
49 | | -exports.readImpl = function (ty) { |
50 | | - return function (offset) { |
51 | | - return function (buf) { |
| 48 | +export function readImpl(ty) { |
| 49 | + return offset => { |
| 50 | + return buf => { |
52 | 51 | return buf["read" + ty](offset); |
53 | 52 | }; |
54 | 53 | }; |
55 | | -}; |
| 54 | +} |
56 | 55 |
|
57 | | -exports.readStringImpl = function (enc) { |
58 | | - return function (start) { |
59 | | - return function (end) { |
60 | | - return function (buff) { |
| 56 | +export function readStringImpl(enc) { |
| 57 | + return start => { |
| 58 | + return end => { |
| 59 | + return buff => { |
61 | 60 | return buff.toString(enc, start, end); |
62 | 61 | }; |
63 | 62 | }; |
64 | 63 | }; |
65 | | -}; |
| 64 | +} |
66 | 65 |
|
67 | | -exports.getAtOffsetImpl = function (just) { |
68 | | - return function (nothing) { |
69 | | - return function (offset) { |
70 | | - return function (buff) { |
| 66 | +export function getAtOffsetImpl(just) { |
| 67 | + return nothing => { |
| 68 | + return offset => { |
| 69 | + return buff => { |
71 | 70 | var octet = buff[offset]; |
72 | 71 | return octet == null ? nothing : just(octet); |
73 | 72 | }; |
74 | 73 | }; |
75 | 74 | }; |
76 | | -}; |
| 75 | +} |
77 | 76 |
|
78 | | -exports.toStringImpl = function (enc) { |
79 | | - return function (buff) { |
| 77 | +export function toStringImpl(enc) { |
| 78 | + return buff => { |
80 | 79 | return buff.toString(enc); |
81 | 80 | }; |
82 | | -}; |
| 81 | +} |
83 | 82 |
|
84 | | -exports.slice = function (start) { |
85 | | - return function (end) { |
86 | | - return function (buff) { |
| 83 | +export function slice(start) { |
| 84 | + return end => { |
| 85 | + return buff => { |
87 | 86 | return buff.slice(start, end); |
88 | 87 | }; |
89 | 88 | }; |
90 | | -}; |
| 89 | +} |
91 | 90 |
|
92 | | -exports.concat = function (buffs) { |
| 91 | +export function concat(buffs) { |
93 | 92 | return Buffer.concat(buffs); |
94 | | -}; |
| 93 | +} |
95 | 94 |
|
96 | | -exports.concatToLength = function (buffs) { |
97 | | - return function (totalLength) { |
| 95 | +export function concatToLength(buffs) { |
| 96 | + return totalLength => { |
98 | 97 | return Buffer.concat(buffs, totalLength); |
99 | 98 | }; |
100 | | -}; |
| 99 | +} |
0 commit comments