blob: b70e1e1bce229d6f72c4aad85bf3c03acacaefe7 [file] [log] [blame]
/*
* similar to dev/null, it consumes the stream without keeping it in memory but
* it tried to decode the steaming bytes as UTF-8 string first
* @tutorial echo "To the black hole!" | p2b google/p2b/[name]/dev/null/text
* @fileoverview
*/
import { View } from 'view';
import { PipeViewer } from 'pipe-viewer';
import { redirectPlay } from 'pipe-viewer-delegation';
class DevNullTextPipeViewer extends PipeViewer {
get name() {
return 'dev/null/text';
}
play(stream) {
stream.setEncoding('utf8');
stream.on('data', (buf) => {
// consume the stream as string
var text = buf.toString();
});
// redirect to regular dev/null to play the stream
var delegatedView = redirectPlay('dev/null', stream);
return delegatedView;
}
}
export default DevNullTextPipeViewer;