blob: 684876360afc5836af104538c71a0f23c92585d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
var fs = require("fs");
var pathUtils = require("path");
var chunkSize = 128;
var chunkTileLength = 3;
var chunksDirectoryPath = "./chunks";
var chunkTileCount = chunkSize * chunkSize
var chunkDataLength = chunkTileCount * chunkTileLength;
var chunkMetadataLength = 1000;
var chunkEntryLength = chunkMetadataLength + chunkDataLength;
var OVEN_TILE = 149;
function getChunkCountInFile(file) {
var tempStats = fs.fstatSync(file);
return tempStats.size / chunkEntryLength;
}
console.log("Analyzing...");
var tempNameList = fs.readdirSync(chunksDirectoryPath);
var tempPathList = [];
var index = 0;
while (index < tempNameList.length) {
var tempName = tempNameList[index];
tempPathList.push(pathUtils.join(chunksDirectoryPath, tempName));
index += 1;
}
var generatedChunkCount = 0;
var ovenCount = 0;
function analyzeChunkBuffer(buffer) {
var index = 0;
while (index < buffer.length) {
var tempTile = buffer[index];
if (tempTile == 0) {
return;
}
if (tempTile == OVEN_TILE) {
ovenCount += 1;
}
index += chunkTileLength;
}
generatedChunkCount += 1;
}
function analyzeChunkFile(path) {
var tempFile = fs.openSync(path, "r+");
var tempCount = getChunkCountInFile(tempFile);
var index = 0;
while (index < tempCount) {
var tempBuffer = Buffer.alloc(chunkDataLength);
fs.readSync(tempFile, tempBuffer, 0, chunkDataLength, index * chunkEntryLength + chunkMetadataLength);
analyzeChunkBuffer(tempBuffer);
index += 1;
}
fs.closeSync(tempFile);
}
var index = 0;
while (index < tempPathList.length) {
var tempPath = tempPathList[index];
analyzeChunkFile(tempPath);
index += 1;
}
console.log("Generated chunk count: " + generatedChunkCount);
console.log("Oven count: " + ovenCount);
|