-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnscutil.ts
More file actions
44 lines (36 loc) · 1.23 KB
/
nscutil.ts
File metadata and controls
44 lines (36 loc) · 1.23 KB
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
/*
NSC utility command line
*/
import { parseArgs } from "util";
import { bunToNodeStream, DataType, readASF } from "./protocol/asf";
import { encode } from "./util/nsc";
import { toUTF16 } from "./util/encoding";
if (Bun.argv.length < 3) {
console.log(`
nscutil - Generates format metadata for NetShow
Usage:
nscutil [asf] [description]
asf The .asf file to generate data for
description Human readable description of format`)
process.exit(1)
}
export const { positionals: args } = parseArgs({allowPositionals: true})
const filePath = args[0]
const file = Bun.file(filePath)
let header;
for await (const data of readASF(bunToNodeStream(file.stream()))) {
if (data.type === DataType.DATA_OBJECT) {
header = data.withHeader
break
}
}
if (!header) {
console.error("Header not found. Is this even an .asf file????")
process.exit(1)
}
// """cryptographically secure hash"""
let hash = Bun.hash.crc32(header)
hash = ((hash & 0xFFFF0000) >> 16) ^ (hash & 0x0000FFFF)
hash = ((hash & 0xF800) >> 8) ^ (hash & 0x07FF)
console.log(`Format=${encode(hash, header)}`)
console.log(`Description=${encode(0, toUTF16(args.slice(1).join(" ") || "Default description for file format", true))}`)