Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

A GBK codec library for Dart developers

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

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]);
}
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);
  });
}
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();
}
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

Exit mobile version