Skip to content
Permalink
Browse files

fix(asset-bundle): fix "generate whole asset bundle" logic

  • Loading branch information...
yyc-git committed Apr 16, 2019
1 parent 357df6b commit a90c52ee33ac61712be016f397edb6a38dfd3870
@@ -64,8 +64,8 @@ module All = {
manifestJsonUint8Array,
);

let ab = ArrayBuffer.make(totalByteLength);
let dataView = DataViewCommon.create(ab);
/* let ab = ArrayBuffer.make(totalByteLength); */
let dataView = DataViewCommon.create(ArrayBuffer.make(totalByteLength));

let byteOffset =
GenerateABUtils.writeHeader(
@@ -121,8 +121,7 @@ let generateAB =
let (jsonByteLength, jsonAlignedByteLength, totalByteLength) =
computeByteLength(bufferTotalAlignedByteLength, jsonUint8Array);

let ab = ArrayBuffer.make(totalByteLength);
let dataView = DataViewCommon.create(ab);
let dataView = DataViewCommon.create(ArrayBuffer.make(totalByteLength));

let byteOffset =
writeHeader(jsonByteLength, bufferTotalAlignedByteLength, dataView);
@@ -0,0 +1,4 @@
type manifest = {
wholeHashIdMap: Js.Dict.t(string),
wholeDependencyRelationMap: Js.Dict.t(array(AllABType.abRelativePath)),
};
@@ -0,0 +1,42 @@
open WABType;

open Js.Typed_array;

let _getHeaderTotalByteLength = () => 4;

let _computeByteLength = jsonUint8Array => {
let jsonByteLength = jsonUint8Array |> Uint8Array.byteLength;

let jsonAlignedByteLength = jsonByteLength |> BufferUtils.alignedLength;

let totalByteLength = _getHeaderTotalByteLength() + jsonAlignedByteLength;

(jsonByteLength, jsonAlignedByteLength, totalByteLength);
};

let _writeHeader = (jsonByteLength, dataView) =>
dataView |> DataViewCommon.writeUint32_1(jsonByteLength, 0);

let generate = (wholeDependencyRelation, wholeHashIdMap) => {
let jsonUint8Array =
{wholeHashIdMap, wholeDependencyRelationMap: wholeDependencyRelation}
|> GenerateABUtils.buildJsonUint8Array;

let (jsonByteLength, jsonAlignedByteLength, totalByteLength) =
_computeByteLength(jsonUint8Array);

let dataView = DataViewCommon.create(ArrayBuffer.make(totalByteLength));

let byteOffset = _writeHeader(jsonByteLength, dataView);

let emptyEncodedUint8Data = GenerateABUtils.getEmptyEncodedUint8Data();

let (byteOffset, _, dataView) =
GenerateABUtils.writeJson(
byteOffset,
(emptyEncodedUint8Data, jsonAlignedByteLength, jsonUint8Array),
dataView,
);

dataView |> DataView.buffer;
};

0 comments on commit a90c52e

Please sign in to comment.
You can’t perform that action at this time.