Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80529 views
1
var B = require('../').Buffer
2
var test = require('tape')
3
if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false
4
5
test('utf8 buffer to base64', function (t) {
6
t.equal(
7
new B('Ձאab', 'utf8').toString('base64'),
8
'1YHXkGFi'
9
)
10
t.end()
11
})
12
13
test('utf8 buffer to hex', function (t) {
14
t.equal(
15
new B('Ձאab', 'utf8').toString('hex'),
16
'd581d7906162'
17
)
18
t.end()
19
})
20
21
test('utf8 to utf8', function (t) {
22
t.equal(
23
new B('öäüõÖÄÜÕ', 'utf8').toString('utf8'),
24
'öäüõÖÄÜÕ'
25
)
26
t.end()
27
})
28
29
test('utf16le to utf16', function (t) {
30
t.equal(
31
new B(new B('abcd', 'utf8').toString('utf16le'), 'utf16le').toString('utf8'),
32
'abcd'
33
)
34
t.end()
35
})
36
37
test('utf16le to hex', function (t) {
38
t.equal(
39
new B('abcd', 'utf16le').toString('hex'),
40
'6100620063006400'
41
)
42
t.end()
43
})
44
45
test('ascii buffer to base64', function (t) {
46
t.equal(
47
new B('123456!@#$%^', 'ascii').toString('base64'),
48
'MTIzNDU2IUAjJCVe'
49
)
50
t.end()
51
})
52
53
test('ascii buffer to hex', function (t) {
54
t.equal(
55
new B('123456!@#$%^', 'ascii').toString('hex'),
56
'31323334353621402324255e'
57
)
58
t.end()
59
})
60
61
test('base64 buffer to utf8', function (t) {
62
t.equal(
63
new B('1YHXkGFi', 'base64').toString('utf8'),
64
'Ձאab'
65
)
66
t.end()
67
})
68
69
test('hex buffer to utf8', function (t) {
70
t.equal(
71
new B('d581d7906162', 'hex').toString('utf8'),
72
'Ձאab'
73
)
74
t.end()
75
})
76
77
test('base64 buffer to ascii', function (t) {
78
t.equal(
79
new B('MTIzNDU2IUAjJCVe', 'base64').toString('ascii'),
80
'123456!@#$%^'
81
)
82
t.end()
83
})
84
85
test('hex buffer to ascii', function (t) {
86
t.equal(
87
new B('31323334353621402324255e', 'hex').toString('ascii'),
88
'123456!@#$%^'
89
)
90
t.end()
91
})
92
93
test('base64 buffer to binary', function (t) {
94
t.equal(
95
new B('MTIzNDU2IUAjJCVe', 'base64').toString('binary'),
96
'123456!@#$%^'
97
)
98
t.end()
99
})
100
101
test('hex buffer to binary', function (t) {
102
t.equal(
103
new B('31323334353621402324255e', 'hex').toString('binary'),
104
'123456!@#$%^'
105
)
106
t.end()
107
})
108
109
test('utf8 to binary', function (t) {
110
/* jshint -W100 */
111
t.equal(
112
new B('öäüõÖÄÜÕ', 'utf8').toString('binary'),
113
'öäüõÖÄÜÕ'
114
)
115
/* jshint +W100 */
116
t.end()
117
})
118
119