Last active
April 22, 2023 20:01
-
-
Save stephanedeluca/62a8c116708e9b331b47a2cf5ed69e0d to your computer and use it in GitHub Desktop.
Dart: makes an https download
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:io'; | |
//import 'dart:convert'; | |
//const c = [0, 0, 184, 84, 0, 2, 40, 3, 100, 65, 36, 97, 0, 1, 0, 0, 0, 0, 0, 0, 8, 252, 0, 0, 0, 2, 167, 120, 119, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 115, 0, 0, 0, 0, 12, 0, 0, 1, 0]; | |
/// @history Create by Sdl on Friday April 21th 2023 | |
/// Expecte results: | |
/// {cache-control: max-age:0, content-length: 24, content-md5: qVT+sY2zlNke425Qebybmw==, content-type: application/octet-stream, date: Fri, 21 Apr 2023 07:35:20 GMT, etag: 0x8DB41BEC85E6579, last-modified: Thu, 20 Apr 2023 16:46:26 GMT, x-ms-blob-type: BlockBlob, x-ms-lease-status: unlocked, x-ms-request-id: cbe6933b-c01e-0002-8023-747c9b000000, x-ms-version: 2009-09-19} | |
/// OK: reponse is: [7, 231, 4, 20, 24, 66, 0, 0, 1, 0, 0, 0, 0, 0, 39, 153, 0, 0, 39, 153, 0, 0, 40, 8] | |
/// File date: 4/20/2023 24:66 | |
/// File format version: 1 | |
/// Critical: b2799 | |
/// Major...: b2799 | |
/// Minor...: b2808 | |
import 'package:http/http.dart' as http; | |
void main() async { | |
try { | |
final r = await http.get( | |
Uri.parse('https://blobs.olenpeps.com/sbm/firmwares/olenergies.pepsr.fu.rules.bin') | |
, headers: { | |
"Cache-control": "no-cache, no-store, must-revalidate", | |
} | |
); | |
print("${r.headers}"); | |
if (r.statusCode!=200) { | |
print("Error ${r.statusCode}"); | |
} | |
//final | |
//print("OK: reponse headers: ${r.headers}"); | |
r.headers.entries.map((e)=>print("${e.key}: ${e.value}")); | |
print("OK: reponse is: ${r.bodyBytes}"); | |
final int year = r.bodyBytes[0]<<8|r.bodyBytes[1]; | |
int i=2; | |
final int month = r.bodyBytes[i++]; | |
final int day = r.bodyBytes[i++]; | |
final int hour = r.bodyBytes[i++]; | |
final int minute = r.bodyBytes[i++]; | |
i += 2; | |
final int version = r.bodyBytes[i++]; | |
final int bCritical = r.bodyBytes[12]<<24|r.bodyBytes[13]<<16|r.bodyBytes[14]<<8|r.bodyBytes[15]; | |
final int bMajor = r.bodyBytes[16]<<24|r.bodyBytes[17]<<16|r.bodyBytes[18]<<8|r.bodyBytes[19]; | |
final int bMinor = r.bodyBytes[20]<<24|r.bodyBytes[21]<<16|r.bodyBytes[22]<<8|r.bodyBytes[23]; | |
print("File date: $month/$day/$year $hour:$minute"); | |
print("File format version: $version"); | |
print("Critical: b${bCritical.toRadixString(16)}"); | |
print("Major...: b${bMajor .toRadixString(16)}"); | |
print("Minor...: b${bMinor .toRadixString(16)}"); | |
//final int | |
}catch(e) { | |
print("Error: $e"); | |
} | |
/* | |
final uint8List = Uint8List.fromList(c); | |
final bdata = ByteData.view(uint8List.buffer); | |
print('bdata: $bdata'); | |
print("afu [0]=c[54]: ${c[54].toRadixString(16)}"); | |
print("afu [1]=c[55]: ${c[55].toRadixString(16)}"); | |
// == Fetch 16-bit date segment | |
int i=53; | |
int raw = 0; | |
if (bdata.lengthInBytes < 54) return; | |
raw = (bdata.getUint8(i++) << 8); | |
if (bdata.lengthInBytes < 55) return; | |
raw |= bdata.getUint8(i++); | |
print("raw: ${raw.toRadixString(16)}"); | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment