Введение
Это мои первые приключения в написании серверной части node.js. Это было до сих пор весело, но я с трудом понимаю правильный путь для реализации чего-то, связанного с потоками node.js.
Проблема
В тестовых и учебных целях я работаю с большими файлами, чьи содержимое zlib сжато. Сжатый контент представляет собой двоичные данные, каждый пакет длиной 38 байт. Я пытаюсь создать результирующий файл который выглядит почти идентично исходному файлу, за исключением того, что есть несжатый 31-байтовый заголовок для каждых 1024 38-байтовых пакетов.
исходное содержимое файла (распаковано)
+----------+----------+----------+----------+
| packet 1 | packet 2 | ...... | packet N |
| 38 bytes | 38 bytes | ...... | 38 bytes |
+----------+----------+----------+----------+
итоговое содержимое файла
+----------+--------------------------------+----------+--------------------------------+
| header 1 | 1024 38 byte packets | header 2 | 1024 38 byte packets |
| 31 bytes | zlib compressed | 31 bytes | zlib compressed |
+----------+--------------------------------+----------+--------------------------------+
Как вы можете видеть, это проблема перевода. Смысл, я взяв некоторый поток источника в качестве входных данных, а затем слегка преобразуя его в некоторый выходной поток. Поэтому было естественным Преобразовать поток.
Класс просто пытается выполнить следующее:
- Принимает поток в качестве ввода
- zlib раздувает куски данных для подсчета количества пакетов, собрав 1024 из них, zlib deflating, и добавление заголовка.
- Пропускает новый результирующий фрагмент через конвейер через
this.push(chunk)
.
Пример использования:
var fs = require('fs');
var me = require('./me'); // Where my Transform stream code sits
var inp = fs.createReadStream('depth_1000000');
var out = fs.createWriteStream('depth_1000000.out');
inp.pipe(me.createMyTranslate()).pipe(out);
Вопрос (ы)
Предполагая, что Трансформация является хорошим выбором для этого варианта использования, я, кажется,
столкнувшись с возможной проблемой противодавления. Мой вызов this.push(chunk)
внутри _transform
продолжает возвращать false
. Почему это было бы и как
обрабатывать такие вещи?