chunk_response.js 589 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict'
  2. const assert = require('check-types').assert
  3. const Chunk = require('./chunk')
  4. /**
  5. * The ChunkResponse allows for additional data to be sent back with the chunk
  6. * at present there are no extra data to send.
  7. */
  8. class ChunkResponse {
  9. constructor(chunk) {
  10. assert.instance(chunk, Chunk)
  11. this.chunk = chunk
  12. }
  13. toRaw() {
  14. return {
  15. chunk: this.chunk.toRaw(),
  16. }
  17. }
  18. static fromRaw(raw) {
  19. if (!raw) return null
  20. return new ChunkResponse(Chunk.fromRaw(raw.chunk))
  21. }
  22. getChunk() {
  23. return this.chunk
  24. }
  25. }
  26. module.exports = ChunkResponse