File: nopad.js

package info (click to toggle)
node-block-stream 0.0.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 132 kB
  • sloc: makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,198 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var BlockStream = require("../")
var tap = require("tap")


tap.test("don't pad, small writes", function (t) {
  var f = new BlockStream(16, { nopad: true })
  t.plan(1)

  f.on("data", function (c) {
    t.equal(c.toString(), "abc", "should get 'abc'")
  })

  f.on("end", function () { t.end() })

  f.write(new Buffer("a"))
  f.write(new Buffer("b"))
  f.write(new Buffer("c"))
  f.end()
})

tap.test("don't pad, exact write", function (t) {
  var f = new BlockStream(16, { nopad: true })
  t.plan(1)

  var first = true
  f.on("data", function (c) {
    if (first) {
      first = false
      t.equal(c.toString(), "abcdefghijklmnop", "first chunk")
    } else {
      t.fail("should only get one")
    }
  })

  f.on("end", function () { t.end() })

  f.end(new Buffer("abcdefghijklmnop"))
})

tap.test("don't pad, big write", function (t) {
  var f = new BlockStream(16, { nopad: true })
  t.plan(2)

  var first = true
  f.on("data", function (c) {
    if (first) {
      first = false
      t.equal(c.toString(), "abcdefghijklmnop", "first chunk")
    } else {
      t.equal(c.toString(), "q")
    }
  })

  f.on("end", function () { t.end() })

  f.end(new Buffer("abcdefghijklmnopq"))
})