debian-mirror-gitlab/app/assets/javascripts/streaming/html_stream.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
817 B
JavaScript
Raw Normal View History

2023-05-27 22:25:52 +05:30
import { ChunkWriter } from '~/streaming/chunk_writer';
export class HtmlStream {
constructor(element) {
const streamDocument = document.implementation.createHTMLDocument('stream');
streamDocument.open();
streamDocument.write('<streaming-element>');
const virtualStreamingElement = streamDocument.querySelector('streaming-element');
element.appendChild(document.adoptNode(virtualStreamingElement));
this.streamDocument = streamDocument;
}
withChunkWriter(config) {
return new ChunkWriter(this, config);
}
write(chunk) {
// eslint-disable-next-line no-unsanitized/method
this.streamDocument.write(chunk);
}
close() {
this.streamDocument.write('</streaming-element>');
this.streamDocument.close();
}
abort() {
this.streamDocument.close();
}
}