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