fast_gbk 0.1.1+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

A GBK codec library for Dart developers.

GBK 编解码器,支持 File 和 HttpClient 的 Stream interface。用法和 utf8 codec完全一致。

Created from templates made available by Stagehand under a BSD-style license.

version #

fast_gbk: 0.1.x

It is a initial version, which will pub to pub.dev when it is stable enough.

Usage #

  • A simple usage example:
import 'package:fast_gbk/fast_gbk.dart';
void main() async {
  var encoded = gbk.encode("白日依山尽,黄河入海流");
  var decoded = gbk.decode([176, 215, 200, 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]);

Features and bugs #

Please feel free to post issue or pull request to this github link.

0.1.1+1 #

export GbkCodec so user could create an instance of GbkCodec with allowMalformed=true

0.1.1 #

fix pub.dev warnings.

0.1.0 #

Initial version, implement GBK codec.

  • support for GBK to String encode and decode.
  • support stream use case in File reading/writing & HttpClient requests&response.

example/README.md

##example.dart

a simple String encode and decode use-case.

import 'package:fast_gbk/fast_gbk.dart';
void main() async {
  // normal usage
  var encoded = gbk.encode("白日依山尽,黄河入海流");
  var decoded = gbk.decode([176, 215, 200, 213, 210, 192, 201, 189, 190, 161, 163,
                            172, 187, 198, 186, 211, 200, 235, 186, 163, 193, 247]);

  //output a �, instead of throw a exception.
  var codec = GbkCodec(allowMalformed: true);
  var decodedMalform = codec.decode([20001]);
}

##example_stream_api.dart

a stream api encode and decode use-case,

  • readGbkFileAndWriteToGbkFile();

Get a gbk input streams from a file, and then write to the file encoding with gbk codec.

  • readUtf8FileAndWriteToGbkFile();

Get a utf8 input streams from a file, and then write to the file encoding with gbk codec.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fast_gbk: ^0.1.1+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fast_gbk/fast_gbk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
30
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:fast_gbk/fast_gbk.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
Dev dependencies
dio ^2.1.16
pedantic ^1.7.0
test ^1.6.0