Skip to content

Commit

Permalink
Save in an isolate when available
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemy-Dev authored and DavBfr committed Mar 11, 2024
1 parent a67f42d commit 462bd71
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions pdf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.11.0

- Save in an isolate when available

## 3.10.8

- Add Flutter's Logical Pixel constant
Expand Down
14 changes: 8 additions & 6 deletions pdf/lib/src/pdf/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ class PdfDocument {

/// Generate the PDF document as a memory file
Future<Uint8List> save() async {
final os = PdfStream();
if (prev != null) {
os.putBytes(prev!.bytes);
}
await _write(os);
return os.output();
return pdfCompute(() async {
final os = PdfStream();
if (prev != null) {
os.putBytes(prev!.bytes);
}
await _write(os);
return os.output();
});
}
}
7 changes: 7 additions & 0 deletions pdf/lib/src/pdf/io/js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ import '../format/object_base.dart';

/// Zip compression function
DeflateCallback defaultDeflate = const ZLibEncoder().encode;

/// The dart:html implementation of [pdfCompute].
@pragma('dart2js:tryInline')
Future<R> pdfCompute<R>(Future<R> Function() computation) async {
await null;
return computation();
}
6 changes: 6 additions & 0 deletions pdf/lib/src/pdf/io/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
*/

import 'dart:io';
import 'dart:isolate';

import '../format/object_base.dart';

/// Zip compression function
DeflateCallback defaultDeflate = zlib.encode;

/// The dart:io implementation of [pdfCompute].
@pragma('vm:prefer-inline')
Future<R> pdfCompute<R>(Future<R> Function() computation) async =>
Isolate.run<R>(computation, debugName: 'dart_pdf');
2 changes: 1 addition & 1 deletion pdf/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ topics:
version: 3.10.8

environment:
sdk: ">=2.18.0 <4.0.0"
sdk: ">=2.19.0 <4.0.0"

dependencies:
archive: ^3.1.0
Expand Down

0 comments on commit 462bd71

Please sign in to comment.