File: basic.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 (27 lines) | stat: -rw-r--r-- 730 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
var tap = require("tap")
  , BlockStream = require("../block-stream.js")

tap.test("basic test", function (t) {
  var b = new BlockStream(16)
  var fs = require("fs")
  var fstr = fs.createReadStream(__filename, {encoding: "utf8"})
  fstr.pipe(b)

  var stat
  t.doesNotThrow(function () {
    stat = fs.statSync(__filename)
  }, "stat should not throw")

  var totalBytes = 0
  b.on("data", function (c) {
    t.equal(c.length, 16, "chunks should be 16 bytes long")
    t.type(c, Buffer, "chunks should be buffer objects")
    totalBytes += c.length
  })
  b.on("end", function () {
    var expectedBytes = stat.size + (16 - stat.size % 16)
    t.equal(totalBytes, expectedBytes, "Should be multiple of 16")
    t.end()
  })

})