Apply module bundling
[platform/framework/web/wrtjs.git] / node_modules / webpack / lib / json / JsonData.js
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         updateHash(hash) {
29                 if (this._buffer === undefined && this._data !== undefined) {
30                         this._buffer = Buffer.from(JSON.stringify(this._data));
31                 }
32
33                 if (this._buffer) return hash.update(this._buffer);
34         }
35 }
36
37 register(JsonData, "webpack/lib/json/JsonData", null, {
38         serialize(obj, { write }) {
39                 if (obj._buffer === undefined && obj._data !== undefined) {
40                         obj._buffer = Buffer.from(JSON.stringify(obj._data));
41                 }
42                 write(obj._buffer);
43         },
44         deserialize({ read }) {
45                 return new JsonData(read());
46         }
47 });
48
49 module.exports = JsonData;