1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var stream_1 = require("stream");
|
5 | var gulp_util_1 = require("gulp-util");
|
6 | var common_1 = require("./common");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var FileContentStream = (function (_super) {
|
13 | tslib_1.__extends(FileContentStream, _super);
|
14 | function FileContentStream(transform, file) {
|
15 | var _this = _super.call(this) || this;
|
16 | _this.transform = transform;
|
17 | _this.file = file;
|
18 | _this.chunks = [];
|
19 | return _this;
|
20 | }
|
21 | FileContentStream.prototype._transform = function (chunk, _encoding, next) {
|
22 | this.chunks.push(chunk);
|
23 | next(null);
|
24 | };
|
25 | FileContentStream.prototype._flush = function (done) {
|
26 | var contents = Buffer.concat(this.chunks);
|
27 | this.transformContents(contents, done);
|
28 | };
|
29 | FileContentStream.prototype.transformContents = function (contents, done) {
|
30 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
31 | var newContents, error_1;
|
32 | return tslib_1.__generator(this, function (_a) {
|
33 | switch (_a.label) {
|
34 | case 0:
|
35 | _a.trys.push([0, 2, , 3]);
|
36 | return [4 , this.transform(contents, this.file)];
|
37 | case 1:
|
38 | newContents = _a.sent();
|
39 | this.push(newContents);
|
40 | done(null);
|
41 | return [3 , 3];
|
42 | case 2:
|
43 | error_1 = _a.sent();
|
44 | done(new gulp_util_1.PluginError(common_1.PLUGIN_NAME, error_1));
|
45 | return [3 , 3];
|
46 | case 3: return [2 ];
|
47 | }
|
48 | });
|
49 | });
|
50 | };
|
51 | return FileContentStream;
|
52 | }(stream_1.Transform));
|
53 | exports.FileContentStream = FileContentStream;
|
54 |
|
\ | No newline at end of file |