Created
March 27, 2021 04:11
-
-
Save dolpheen/0f9c5db9da3426579d4c37011723b5fa to your computer and use it in GitHub Desktop.
Decode sksl.json files generated by flutter run --profile --cache-sksl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'dart:io'; | |
void main(List<String> args) async { | |
if (args.isEmpty || args.length > 1) { | |
print('The program decodes flutter sksl.json cache files\n'); | |
print('Usage: dart main.dart <skslJsonFile>'); | |
exit(1); | |
} | |
final String inputFileName = args[0]; | |
if (!File(inputFileName).existsSync()) { | |
print('Error: file $inputFileName does not exists'); | |
exit(1); | |
} | |
final String content = File(inputFileName).readAsStringSync(); | |
final Map<String, dynamic> skslJson = jsonDecode(content); | |
print(skslJson['platform']); | |
print(skslJson['name']); | |
print(skslJson['engineRevision']); | |
final Map<String, dynamic> skslData = skslJson['data']; | |
List<int> outputBuffer = []; | |
for (String encodedValue in skslData.values) { | |
final String stripped = encodedValue.substring(16); | |
final Iterable<int> decoded = | |
base64Decode(stripped).where((element) => element != 0); | |
outputBuffer.addAll(decoded); | |
} | |
final String outputFilename = inputFileName + '.glsl'; | |
File(outputFilename).writeAsBytesSync(outputBuffer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment