Prepend magic number to unbundle files

Summary:
In order to be able to reliable identify unbundles when loading files, prepend a magic number (0xFB0BD1E5)
public

Reviewed By: martinbigio

Differential Revision: D2734359

fb-gh-sync-id: b469e26459234e7f6270fffa0b872a93d137381d
This commit is contained in:
David Aurelio 2015-12-08 10:58:35 -08:00 committed by facebook-github-bot-5
parent c489660f26
commit d013554083
1 changed files with 4 additions and 1 deletions

View File

@ -12,6 +12,7 @@ const fs = require('fs');
const Promise = require('promise');
const writeFile = require('./writeFile');
const MAGIC_UNBUNDLE_FILE_HEADER = 0xFB0BD1E5;
const MAGIC_STARTUP_MODULE_ID = '';
function buildBundle(packagerClient, requestOptions) {
@ -49,6 +50,8 @@ function saveUnbundle(bundle, options, log) {
}
/* global Buffer: true */
const fileHeader = Buffer(4);
fileHeader.writeUInt32LE(MAGIC_UNBUNDLE_FILE_HEADER);
const nullByteBuffer = Buffer(1).fill(0);
const moduleToBuffer = ({name, code}, encoding) => ({
@ -109,7 +112,7 @@ function buildModuleTable(buffers) {
function buildTableAndContents(startupCode, modules, encoding) {
const buffers = buildModuleBuffers(startupCode, modules, encoding);
const table = buildModuleTable(buffers, encoding);
return [table].concat(buffers.map(({buffer}) => buffer));
return [fileHeader, table].concat(buffers.map(({buffer}) => buffer));
}
function writeBuffers(stream, buffers) {