1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const { register } = require("../util/serialization");
|
9 |
|
10 | class JsonData {
|
11 | constructor(data) {
|
12 | this._buffer = undefined;
|
13 | this._data = undefined;
|
14 | if (Buffer.isBuffer(data)) {
|
15 | this._buffer = data;
|
16 | } else {
|
17 | this._data = data;
|
18 | }
|
19 | }
|
20 |
|
21 | get() {
|
22 | if (this._data === undefined && this._buffer !== undefined) {
|
23 | this._data = JSON.parse(this._buffer.toString());
|
24 | }
|
25 | return this._data;
|
26 | }
|
27 | }
|
28 |
|
29 | register(JsonData, "webpack/lib/json/JsonData", null, {
|
30 | serialize(obj, { write }) {
|
31 | if (obj._buffer === undefined && obj._data !== undefined) {
|
32 | obj._buffer = Buffer.from(JSON.stringify(obj._data));
|
33 | }
|
34 | write(obj._buffer);
|
35 | },
|
36 | deserialize({ read }) {
|
37 | return new JsonData(read());
|
38 | }
|
39 | });
|
40 |
|
41 | module.exports = JsonData;
|