Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
842 bytes
|
Line | |
---|
1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
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;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.