A GBK codec library for Dart developers.

Related tags

Templates fast_gbk
Overview

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: 1.0.0

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

Q: null safety support? A: 1.0.0 version supports null safety.

Features and bugs

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

You might also like...

A super powerful widget to help developers build complex views quickly and comfortably.

A super powerful widget to help developers build complex views quickly and comfortably.

FSuper FSuper can help developers build complex views quickly and comfortably. It supports rich text, rounded corners, borders, pictures, small red do

Dec 29, 2022

More than 130+ pages in this beautiful app and more than 45 developers has contributed to it.

More than 130+ pages in this beautiful app and more than 45 developers has contributed to it.

flutter-ui-nice ❤️ Star ❤️ the repo to support the project or 😄 Follow Me.Thanks! Facebook Page Twitter Medium QQ Group Flutter Open NieBin Flutter O

Jan 3, 2023

Be together, whenever. A simple way to text chat and plan things all in one place for flutter developers.

Be together, whenever. A simple way to text chat and plan things all in one place for flutter developers.

Flutterdevconnect Be together, whenever. A simple way to text chat and plan things all in one place for flutter developers. Android IOS Web PWA Androi

Aug 27, 2022

From then on, developers only need to master one Button component, which is enough.

From then on, developers only need to master one Button component, which is enough.

FButton From then on, developers only need to master one Button component, which is enough. Support corners, borders, icons, special effects, loading

Nov 22, 2022

Help developers build the most beautiful search bar🍹.

Help developers build the most beautiful search bar🍹.

fsearch Help developers build the most beautiful search bar 🍹 . [FSearch] provides developers with a one-stop search bar construction service. Suppor

Oct 28, 2022

Software analytics tool that helps developers analyse and improve software quality.

Software analytics tool that helps developers analyse and improve software quality.

Dart Code Metrics Note: you can find the full documentation on the website Configuration | Rules | Metrics | Anti-patterns Dart Code Metrics is a stat

Dec 26, 2022

A TabBarController that is easy to use for flutter developers. 🥰 It supports various styles of page navigation, and you can also use it to customize your favorite styles. 🍻🍻

A TabBarController that is easy to use for flutter developers. 🥰 It supports various styles of page navigation, and you can also use it to customize your favorite styles. 🍻🍻

easy_tab_controller A user-friendly TabBarController widget for flutter developer. Getting Started This project is a starting point for a Flutter plug

May 26, 2022

Collection of cool Layouts built with Flutter to Inspire Other UI developers and explore the possibilities of Flutter.

Collection of cool Layouts built with Flutter to Inspire Other UI developers and explore the possibilities of Flutter.

Awesome_Flutter_Layouts Would you like to Contribute your Designs? Please refer the Contribution guidelines before you dive In Need help? or Looks Som

Nov 22, 2022

More than 130+ pages in this beautiful app and more than 45 developers has contributed to it.

More than 130+ pages in this beautiful app and more than 45 developers has contributed to it.

flutter-ui-nice ❤️ Star ❤️ the repo to support the project or 😄 Follow Me.Thanks! Facebook Page Twitter Medium QQ Group Flutter Open NieBin Flutter O

Jan 5, 2023
Comments
  • 对GB18030编码支持不完全

    对GB18030编码支持不完全

    解析GB18030的网页时遇到了编码超出范围的问题,网页地址http://www.jjwxc.net/onebook.php?novelid=3433838&chapterid=1 ,报错信息为”出现异常。FormatException (FormatException: Bad GBK encoding 0xb120)“ ,如下图: fast_gbk_error 换用gbk2utf8解码正常,但是速度太慢,严重影响使用。希望fast_gbk可以增加GB18030编码支持。

    opened by mabDc 4
Owner
Xiang Li
Xiang Li
DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures!

dice_bear Flutter Package DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures! C

Zaif Senpai 8 Oct 31, 2022
Magpie-fly is a component library produced by 58 Group, which encapsulates a variety of common components to meet the needs of developers

[toc] magpie_fly Magpie-fly 是58集体出品组件库,封装了多种常用组件,以满足开发者需求。(Magpie-fly is a component library produced by 58 Group, which encapsulates a variety of com

Wuba 40 Mar 18, 2022
Dart package to get GitHub trending repositories and developers

github_trending A Dart library to get GitHub trending repositories and developers via github-trending-api. Installation Add github_trending as a depen

GitTouch 6 Oct 22, 2022
This is an open source Tips & Tricks for Flutter, that helps flutter Developers write simple but powerful dart codes.

Showcasing-flutter - This is an open source Tips & Tricks for Flutter, that helps flutter Developers write simple but powerful dart codes.

Paul Edeme'kong - Flutter Fairy 1 Jan 4, 2022
Scouter is a package which was made following the goal to provide a NestJS-like experience to Dart Developers that want to develop Rest APIS

Scouter is a package which was made following the goal to provide a NestJS-like experience to Dart Developers that want to develop Rest APIS Features

Vinicius Amélio 3 Sep 12, 2022
A middleware library for Dart's http library.

http_middleware A middleware library for Dart http library. Getting Started http_middleware is a module that lets you build middleware for Dart's http

TED Consulting 38 Oct 23, 2021
This library provides the easiest and powerful Dart/Flutter library for Mastodon API 🎯

The Easiest and Powerful Dart/Flutter Library for Mastodon API ?? 1. Guide ?? 1.1. Features ?? 1.2. Getting Started ⚡ 1.2.1. Install Library 1.2.2. Im

Mastodon.dart 55 Jul 27, 2023
Flutter Multi-platform allows developers to unleash their app to run on the wide variety of different platforms with little or no change.

Flutter Multi-platform sample Flutter Multi-platform allows developers to unleash their app to run on the wide variety of different platforms with lit

MindInventory 22 Dec 31, 2022
Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.

supabase_flutter Flutter package for Supabase. What is Supabase Supabase is an open source Firebase alternative. We are a service to: listen to databa

Supabase 251 Jan 7, 2023
A flutter package that developers have pretty logs instead just printing everything like a newbie

A flutter package that developers have pretty logs instead just printing everything like a newbie. Features Makes it easy to log to console without us

null 2 Nov 28, 2021