Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "pub" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
42 changes: 42 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Dart

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# Note: This workflow uses the latest stable version of the Dart SDK.
# You can specify other versions if desired, see documentation here:
# https://github.com/dart-lang/setup-dart/blob/main/README.md
# - uses: dart-lang/setup-dart@v1
- uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603

- name: Install dependencies
run: dart pub get

# Verify the use of 'dart format' on each commit.
- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: dart analyze

# Your project will need to have tests in test/ and a dependency on
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
10 changes: 10 additions & 0 deletions .idx/mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"mcpServers": {
"dart": {
"command": "dart",
"args": [
"mcp-server"
]
}
}
}
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.0

- Initial version.
- Initial release of the `base32_codec` package.
- Supports RFC 4648, RFC 4648 "Hex", and Crockford's Base32 alphabets.
- Provides a `Codec`-based API for synchronous and asynchronous (stream-based)
encoding and decoding.
125 changes: 101 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,116 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
[![pub package](https://img.shields.io/pub/v/base32_codec.svg)](https://pub.dev/packages/base32_codec)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![Open in Firebase Studio](https://cdn.firebasestudio.dev/btn/open_light_20.svg)](https://studio.firebase.google.com/import?url=https%3A%2F%2Fgithub.com%2Fdropbear-software%2Fbase32_codec)

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).

For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
A flexible and efficient Dart package for encoding and decoding Base32 data.
This package provides a `Codec`-based API that aligns with `dart:convert`
conventions, making it easy to work with synchronous and asynchronous data
streams.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.
* **Multiple Variants:** Supports RFC 4648, RFC 4648 "Hex", and Crockford's
Base32 alphabets.
* **Stream-Compatible:** Implements chunked conversion, allowing it to be
used as a `StreamTransformer` for efficient processing of large data.
* **Dart Native:** A pure Dart implementation with no platform-specific
dependencies.
* **Well-Tested:** Comes with a comprehensive test suite, including RFC 4648
test vectors.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.
Add this package to your `pubspec.yaml` file:

```yaml
dependencies:
base32_codec: ^1.0.0 # Replace with the latest version
```

Then, run `pub get` or `flutter pub get` to install the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
### Synchronous Conversion

For simple, in-memory encoding and decoding, you can use the `encode` and
`decode` methods directly.

**Default (RFC 4648)**

```dart
const like = 'sample';
import 'dart:convert';
import 'package:base32_codec/base32_codec.dart';

void main() {
final codec = Base32Codec();
final data = ascii.encode('foobar');

final encoded = codec.encode(data);
print(encoded); // MZXW6YTBOI======

final decoded = codec.decode(encoded);
print(ascii.decode(decoded)); // foobar
}
```

## Additional information
**Crockford Variant**

To use a different variant, instantiate the corresponding codec.

```dart
import 'dart:convert';
import 'package:base32_codec/base32_codec.dart';

void main() {
final codec = Base32Codec.crockford();
final data = ascii.encode('foobar');

final encoded = codec.encode(data);
print(encoded); // CSQPYRK1E8

final decoded = codec.decode(encoded);
print(ascii.decode(decoded)); // foobar
}
```

### Asynchronous (Stream) Conversion

For handling larger data, like files or network streams, you can use the
codec's encoder and decoder as a `StreamTransformer`.

```dart
import 'dart:convert';
import 'dart:io';
import 'package:base32_codec/base32_codec.dart';

Future<void> main() async {
// Create a stream from a file or network source
final inputStream = Stream.value(ascii.encode('foobar'));

// Transform the stream by encoding it
final encodedStream = inputStream.transform(Base32Codec().encoder);

// Print each chunk of the encoded output
await for (final chunk in encodedStream) {
print(chunk); // MZXW6YTBOI======
}

// You can also pipe the stream to a file
// await inputStream
// .transform(Base32Codec().encoder)
// .pipe(File('output.txt').openWrite());
}
```

## Contributing

This package is open source and contributions are welcome!

If you find a bug or have a feature request, please file an issue on the
[GitHub issue tracker](https://github.com/dropbear-software/base32_codec/issues). When
filing an issue, please provide a clear description of the problem and include
a minimal, reproducible example if possible.

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
If you would like to contribute code, please fork the repository and submit a
pull request.
97 changes: 83 additions & 14 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,87 @@

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.
analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
exclude:
- example/base32_codec_example.dart

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
linter:
rules:
- always_put_required_named_parameters_first
- always_use_package_imports
- annotate_redeclares
- avoid_annotating_with_dynamic
- avoid_bool_literals_in_conditional_expressions
- avoid_catches_without_on_clauses
- avoid_catching_errors
- avoid_classes_with_only_static_members
- avoid_double_and_int_checks
- avoid_dynamic_calls
- avoid_equals_and_hash_code_on_mutable_classes
- avoid_escaping_inner_quotes
- avoid_field_initializers_in_const_classes
- avoid_final_parameters
- avoid_futureor_void
- avoid_js_rounded_ints
- avoid_multiple_declarations_per_line
- avoid_positional_boolean_parameters
- avoid_print
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_returning_this
- avoid_setters_without_getters
- avoid_unused_constructor_parameters
- avoid_void_async
- combinators_ordering
- comment_references
- conditional_uri_does_not_exist
- deprecated_consistency
- directives_ordering
- discarded_futures
- do_not_use_environment
- document_ignores
- implicit_reopen
- invalid_runtime_check_with_js_interop_types
- leading_newlines_in_multiline_strings
- matching_super_parameters
- missing_code_block_language_in_doc_comment
- no_literal_bool_comparisons
- noop_primitive_operations
- omit_local_variable_types
- only_throw_errors
- prefer_asserts_in_initializer_lists
- prefer_asserts_with_message
- prefer_constructors_over_static_methods
- prefer_final_in_for_each
- prefer_final_locals
- prefer_if_elements_to_conditional_expressions
- prefer_single_quotes
- public_member_api_docs
- sort_pub_dependencies
- strict_top_level_inference
- throw_in_finally
- unawaited_futures
- unintended_html_in_doc_comment
- unnecessary_async
- unnecessary_await_in_return
- unnecessary_breaks
- unnecessary_ignore
- unnecessary_lambdas
- unnecessary_library_directive
- unnecessary_library_name
- unnecessary_parenthesis
- unnecessary_raw_strings
- unnecessary_statements
- unnecessary_underscores
- unreachable_from_main
- unsafe_variance
- use_if_null_to_convert_nulls_to_bools
- use_is_even_rather_than_modulo
- use_named_constants
- use_null_aware_elements
- use_raw_strings
- use_truncating_division
Loading