A GBK codec library for Dart developers.
GBK codec, support Stream interface of File and HttpClient. The usage is exactly the same as the utf8 codec.
Created from templates made available by Stagehand under a BSD-style license.
version
fast_gbk: 1.0.0
Usage
- A simple usage example:
Import 'Package: fast_gbk / fast_gbk.dart' ; void main () the async { var encoded = GBK. encode ( "sun mountains, the ocean currents Yellow" ); var Decoded = GBK. decode ([ 176 , 215 , 200 is , 213 , 210 , 192 , 201 , 189 , 190 , 161 , 163 , 172 , 187 ,198, 186, 211, 200, 235, 186, 163, 193, 247]); }
- Example: read a GBK file.
import 'dart:convert'; import 'dart:io'; import 'package:fast_gbk/fast_gbk.dart'; void main() { File gbkFile = File("gbkFile.txt"); var stream = gbkFile.openRead(); stream.transform(gbk.decoder) .transform(const LineSplitter()) .listen((line) { stdout.writeln(line); }); }
- Example: write a GBK file.
import 'dart:io'; import 'package:fast_gbk/fast_gbk.dart'; void main() async { File output = File("gbk.txt"); var stream = output.openWrite(encoding: gbk); stream.write("123"); stream.writeln("456"); stream.writeCharCode(0x41); await stream.close(); }
- Example: decode HttpClient response
import 'dart:io'; import 'package:fast_gbk/fast_gbk.dart'; void main() async { var gbkWebUrl = "http://www.newsmth.net/nForum/#!mainpage"; var httpClient = HttpClient(); HttpClientRequest request = await httpClient.getUrl(Uri.parse(gbkWebUrl)); HttpClientResponse response = await request.close(); var responseBody = await response.transform(gbk.decoder).join(); print(responseBody); httpClient.close(); }
FAQ
Q: support for malformed gbk characters.
Q: when input string contains malformed GBK characters, we do not want to received a exception.
A: 0.1.1+1 export GbkCodec api, users can use as follows:
//output a �, instead of throw a exception. var codec = GbkCodec(allowMalformed: true); var decodedMalform = codec.decode([20001]);
Q: null safety support? A: 1.0.0 version supports null safety.
Download source code on GitHub
Provides the list of the opensource Flutter apps collection with GitHub repository.