From a77ec4bedb2da8320db2308b5448df3ed0928e95 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 10 Mar 2021 11:35:14 -0800 Subject: [PATCH] [cross_file] Delete. The package now lives in flutter/packages. --- CODEOWNERS | 1 - packages/cross_file/CHANGELOG.md | 30 ---- packages/cross_file/LICENSE | 25 ---- packages/cross_file/README.md | 34 ----- packages/cross_file/lib/cross_file.dart | 5 - packages/cross_file/lib/src/types/base.dart | 86 ----------- packages/cross_file/lib/src/types/html.dart | 135 ------------------ .../cross_file/lib/src/types/interface.dart | 58 -------- packages/cross_file/lib/src/types/io.dart | 115 --------------- .../lib/src/web_helpers/web_helpers.dart | 38 ----- packages/cross_file/lib/src/x_file.dart | 7 - packages/cross_file/pubspec.yaml | 18 --- packages/cross_file/test/assets/hello.txt | 1 - .../cross_file/test/x_file_html_test.dart | 106 -------------- packages/cross_file/test/x_file_io_test.dart | 90 ------------ 15 files changed, 749 deletions(-) delete mode 100644 packages/cross_file/CHANGELOG.md delete mode 100644 packages/cross_file/LICENSE delete mode 100644 packages/cross_file/README.md delete mode 100644 packages/cross_file/lib/cross_file.dart delete mode 100644 packages/cross_file/lib/src/types/base.dart delete mode 100644 packages/cross_file/lib/src/types/html.dart delete mode 100644 packages/cross_file/lib/src/types/interface.dart delete mode 100644 packages/cross_file/lib/src/types/io.dart delete mode 100644 packages/cross_file/lib/src/web_helpers/web_helpers.dart delete mode 100644 packages/cross_file/lib/src/x_file.dart delete mode 100644 packages/cross_file/pubspec.yaml delete mode 100644 packages/cross_file/test/assets/hello.txt delete mode 100644 packages/cross_file/test/x_file_html_test.dart delete mode 100644 packages/cross_file/test/x_file_io_test.dart diff --git a/CODEOWNERS b/CODEOWNERS index 01732888ad89..8ab65bbb5a63 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -6,7 +6,6 @@ packages/camera/** @bparrishMines -packages/cross_file/** @ditman @mvanbeusekom packages/file_selector/** @ditman packages/google_maps_flutter/** @cyanglaz packages/image_picker/** @cyanglaz diff --git a/packages/cross_file/CHANGELOG.md b/packages/cross_file/CHANGELOG.md deleted file mode 100644 index 94bf4b29322a..000000000000 --- a/packages/cross_file/CHANGELOG.md +++ /dev/null @@ -1,30 +0,0 @@ -## 0.3.1 - -* Fix nullability of `XFileBase`'s `path` and `name` to match the - implementations to avoid potential analyzer issues. - -## 0.3.0 - -* Migrated package to null-safety. -* **breaking change** According to our unit tests, the API should be backwards-compatible. Some relevant changes were made, however: - * Web: `lastModified` returns the epoch time as a default value, to maintain the `Future` return type (and not `null`) - -## 0.2.1 - -* Prepare for breaking `package:http` change. - -## 0.2.0 - -* **breaking change** Make sure the `saveTo` method returns a `Future` so it can be awaited and users are sure the file has been written to disk. - -## 0.1.0+2 - -* Fix outdated links across a number of markdown files ([#3276](https://github.com/flutter/plugins/pull/3276)) - -## 0.1.0+1 - -* Update Flutter SDK constraint. - -## 0.1.0 - -* Initial open-source release. diff --git a/packages/cross_file/LICENSE b/packages/cross_file/LICENSE deleted file mode 100644 index 2c91f1438173..000000000000 --- a/packages/cross_file/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright 2020 The Flutter Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of Google Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/packages/cross_file/README.md b/packages/cross_file/README.md deleted file mode 100644 index 65bd41896184..000000000000 --- a/packages/cross_file/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# cross_file - -An abstraction to allow working with files across multiple platforms. - -# Usage - -Import `package:cross/cross_info.dart`, instantiate a `CrossFile` -using a path or byte array and use its methods and properties to -access the file and its metadata. - -Example: - -```dart -import 'package:cross_file/cross_file.dart'; - -final file = CrossFile('assets/hello.txt'); - -print('File information:'); -print('- Path: ${file.path}'); -print('- Name: ${file.name}'); -print('- MIME type: ${file.mimeType}'); - -final fileContent = await file.readAsString(); -print('Content of the file: ${fileContent}'); // e.g. "Moto G (4)" -``` - -You will find links to the API docs on the [pub page](https://pub.dev/packages/cross_file). - -## Getting Started - -For help getting started with Flutter, view our online -[documentation](http://flutter.io/). - -For help on editing plugin code, view the [documentation](https://flutter.io/platform-plugins/#edit-code). \ No newline at end of file diff --git a/packages/cross_file/lib/cross_file.dart b/packages/cross_file/lib/cross_file.dart deleted file mode 100644 index a3e2873e670d..000000000000 --- a/packages/cross_file/lib/cross_file.dart +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -export 'src/x_file.dart'; diff --git a/packages/cross_file/lib/src/types/base.dart b/packages/cross_file/lib/src/types/base.dart deleted file mode 100644 index 4522b7343c9b..000000000000 --- a/packages/cross_file/lib/src/types/base.dart +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:convert'; -import 'dart:typed_data'; - -/// The interface for a CrossFile. -/// -/// A CrossFile is a container that wraps the path of a selected -/// file by the user and (in some platforms, like web) the bytes -/// with the contents of the file. -/// -/// This class is a very limited subset of dart:io [File], so all -/// the methods should seem familiar. -abstract class XFileBase { - /// Construct a CrossFile - XFileBase(String? path); - - /// Save the CrossFile at the indicated file path. - Future saveTo(String path) { - throw UnimplementedError('saveTo has not been implemented.'); - } - - /// Get the path of the picked file. - /// - /// This should only be used as a backwards-compatibility clutch - /// for mobile apps, or cosmetic reasons only (to show the user - /// the path they've picked). - /// - /// Accessing the data contained in the picked file by its path - /// is platform-dependant (and won't work on web), so use the - /// byte getters in the CrossFile instance instead. - String get path { - throw UnimplementedError('.path has not been implemented.'); - } - - /// The name of the file as it was selected by the user in their device. - /// - /// Use only for cosmetic reasons, do not try to use this as a path. - String get name { - throw UnimplementedError('.name has not been implemented.'); - } - - /// For web, it may be necessary for a file to know its MIME type. - String? get mimeType { - throw UnimplementedError('.mimeType has not been implemented.'); - } - - /// Get the length of the file. Returns a `Future` that completes with the length in bytes. - Future length() { - throw UnimplementedError('.length() has not been implemented.'); - } - - /// Synchronously read the entire file contents as a string using the given [Encoding]. - /// - /// By default, `encoding` is [utf8]. - /// - /// Throws Exception if the operation fails. - Future readAsString({Encoding encoding = utf8}) { - throw UnimplementedError('readAsString() has not been implemented.'); - } - - /// Synchronously read the entire file contents as a list of bytes. - /// - /// Throws Exception if the operation fails. - Future readAsBytes() { - throw UnimplementedError('readAsBytes() has not been implemented.'); - } - - /// Create a new independent [Stream] for the contents of this file. - /// - /// If `start` is present, the file will be read from byte-offset `start`. Otherwise from the beginning (index 0). - /// - /// If `end` is present, only up to byte-index `end` will be read. Otherwise, until end of file. - /// - /// In order to make sure that system resources are freed, the stream must be read to completion or the subscription on the stream must be cancelled. - Stream openRead([int? start, int? end]) { - throw UnimplementedError('openRead() has not been implemented.'); - } - - /// Get the last-modified time for the CrossFile - Future lastModified() { - throw UnimplementedError('openRead() has not been implemented.'); - } -} diff --git a/packages/cross_file/lib/src/types/html.dart b/packages/cross_file/lib/src/types/html.dart deleted file mode 100644 index 203ab5d82e12..000000000000 --- a/packages/cross_file/lib/src/types/html.dart +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:convert'; -import 'dart:html'; -import 'dart:typed_data'; - -import 'package:meta/meta.dart'; - -import './base.dart'; -import '../web_helpers/web_helpers.dart'; - -/// A CrossFile that works on web. -/// -/// It wraps the bytes of a selected file. -class XFile extends XFileBase { - late String path; - - final String? mimeType; - final Uint8List? _data; - final int? _length; - final String name; - final DateTime? _lastModified; - - late Element _target; - - final CrossFileTestOverrides? _overrides; - - bool get _hasTestOverrides => _overrides != null; - - /// Construct a CrossFile object from its ObjectUrl. - /// - /// Optionally, this can be initialized with `bytes` and `length` - /// so no http requests are performed to retrieve files later. - /// - /// `name` needs to be passed from the outside, since we only have - /// access to it while we create the ObjectUrl. - XFile( - this.path, { - this.mimeType, - String? name, - int? length, - Uint8List? bytes, - DateTime? lastModified, - @visibleForTesting CrossFileTestOverrides? overrides, - }) : _data = bytes, - _length = length, - _overrides = overrides, - _lastModified = lastModified ?? DateTime.fromMillisecondsSinceEpoch(0), - name = name ?? '', - super(path); - - /// Construct an CrossFile from its data - XFile.fromData( - Uint8List bytes, { - this.mimeType, - String? name, - int? length, - DateTime? lastModified, - String? path, - @visibleForTesting CrossFileTestOverrides? overrides, - }) : _data = bytes, - _length = length, - _overrides = overrides, - _lastModified = lastModified ?? DateTime.fromMillisecondsSinceEpoch(0), - name = name ?? '', - super(path) { - if (path == null) { - final blob = (mimeType == null) ? Blob([bytes]) : Blob([bytes], mimeType); - this.path = Url.createObjectUrl(blob); - } else { - this.path = path; - } - } - - @override - Future lastModified() async => Future.value(_lastModified); - - Future get _bytes async { - if (_data != null) { - return Future.value(UnmodifiableUint8ListView(_data!)); - } - - // We can force 'response' to be a byte buffer by passing responseType: - ByteBuffer? response = - (await HttpRequest.request(path, responseType: 'arraybuffer')).response; - - return response?.asUint8List() ?? Uint8List(0); - } - - @override - Future length() async => _length ?? (await _bytes).length; - - @override - Future readAsString({Encoding encoding = utf8}) async { - return encoding.decode(await _bytes); - } - - @override - Future readAsBytes() async => Future.value(await _bytes); - - @override - Stream openRead([int? start, int? end]) async* { - final bytes = await _bytes; - yield bytes.sublist(start ?? 0, end ?? bytes.length); - } - - /// Saves the data of this CrossFile at the location indicated by path. - /// For the web implementation, the path variable is ignored. - Future saveTo(String path) async { - // Create a DOM container where we can host the anchor. - _target = ensureInitialized('__x_file_dom_element'); - - // Create an tag with the appropriate download attributes and click it - // May be overridden with CrossFileTestOverrides - final AnchorElement element = _hasTestOverrides - ? _overrides!.createAnchorElement(this.path, this.name) as AnchorElement - : createAnchorElement(this.path, this.name); - - // Clear the children in our container so we can add an element to click - _target.children.clear(); - addElementToContainerAndClick(_target, element); - } -} - -/// Overrides some functions to allow testing -@visibleForTesting -class CrossFileTestOverrides { - /// For overriding the creation of the file input element. - Element Function(String href, String suggestedName) createAnchorElement; - - /// Default constructor for overrides - CrossFileTestOverrides({required this.createAnchorElement}); -} diff --git a/packages/cross_file/lib/src/types/interface.dart b/packages/cross_file/lib/src/types/interface.dart deleted file mode 100644 index 122f3d1d9364..000000000000 --- a/packages/cross_file/lib/src/types/interface.dart +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:typed_data'; -import 'package:meta/meta.dart'; - -import './base.dart'; - -/// A CrossFile is a cross-platform, simplified File abstraction. -/// -/// It wraps the bytes of a selected file, and its (platform-dependant) path. -class XFile extends XFileBase { - /// Construct a CrossFile object from its path. - /// - /// Optionally, this can be initialized with `bytes` and `length` - /// so no http requests are performed to retrieve data later. - /// - /// `name` may be passed from the outside, for those cases where the effective - /// `path` of the file doesn't match what the user sees when selecting it - /// (like in web) - XFile( - String path, { - String? mimeType, - String? name, - int? length, - Uint8List? bytes, - DateTime? lastModified, - @visibleForTesting CrossFileTestOverrides? overrides, - }) : super(path) { - throw UnimplementedError( - 'CrossFile is not available in your current platform.'); - } - - /// Construct a CrossFile object from its data - XFile.fromData( - Uint8List bytes, { - String? mimeType, - String? name, - int? length, - DateTime? lastModified, - String? path, - @visibleForTesting CrossFileTestOverrides? overrides, - }) : super(path) { - throw UnimplementedError( - 'CrossFile is not available in your current platform.'); - } -} - -/// Overrides some functions of CrossFile for testing purposes -@visibleForTesting -class CrossFileTestOverrides { - /// For overriding the creation of the file input element. - dynamic Function(String href, String suggestedName) createAnchorElement; - - /// Default constructor for overrides - CrossFileTestOverrides({required this.createAnchorElement}); -} diff --git a/packages/cross_file/lib/src/types/io.dart b/packages/cross_file/lib/src/types/io.dart deleted file mode 100644 index 6eafaf0ce0cc..000000000000 --- a/packages/cross_file/lib/src/types/io.dart +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:convert'; -import 'dart:io'; -import 'dart:typed_data'; - -import './base.dart'; - -/// A CrossFile backed by a dart:io File. -class XFile extends XFileBase { - final File _file; - final String? mimeType; - final DateTime? _lastModified; - int? _length; - - final Uint8List? _bytes; - - /// Construct a CrossFile object backed by a dart:io File. - XFile( - String path, { - this.mimeType, - String? name, - int? length, - Uint8List? bytes, - DateTime? lastModified, - }) : _file = File(path), - _bytes = null, - _lastModified = lastModified, - super(path); - - /// Construct an CrossFile from its data - XFile.fromData( - Uint8List bytes, { - this.mimeType, - String? path, - String? name, - int? length, - DateTime? lastModified, - }) : _bytes = bytes, - _file = File(path ?? ''), - _length = length, - _lastModified = lastModified, - super(path) { - if (length == null) { - _length = bytes.length; - } - } - - @override - Future lastModified() { - if (_lastModified != null) { - return Future.value(_lastModified); - } - return _file.lastModified(); - } - - @override - Future saveTo(String path) async { - File fileToSave = File(path); - await fileToSave.writeAsBytes(_bytes ?? (await readAsBytes())); - await fileToSave.create(); - } - - @override - String get path { - return _file.path; - } - - @override - String get name { - return _file.path.split(Platform.pathSeparator).last; - } - - @override - Future length() { - if (_length != null) { - return Future.value(_length); - } - return _file.length(); - } - - @override - Future readAsString({Encoding encoding = utf8}) { - if (_bytes != null) { - return Future.value(String.fromCharCodes(_bytes!)); - } - return _file.readAsString(encoding: encoding); - } - - @override - Future readAsBytes() { - if (_bytes != null) { - return Future.value(_bytes); - } - return _file.readAsBytes(); - } - - Stream _getBytes(int? start, int? end) async* { - final bytes = _bytes!; - yield bytes.sublist(start ?? 0, end ?? bytes.length); - } - - @override - Stream openRead([int? start, int? end]) { - if (_bytes != null) { - return _getBytes(start, end); - } else { - return _file - .openRead(start ?? 0, end) - .map((chunk) => Uint8List.fromList(chunk)); - } - } -} diff --git a/packages/cross_file/lib/src/web_helpers/web_helpers.dart b/packages/cross_file/lib/src/web_helpers/web_helpers.dart deleted file mode 100644 index a963e9933f99..000000000000 --- a/packages/cross_file/lib/src/web_helpers/web_helpers.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:html'; - -/// Create anchor element with download attribute -AnchorElement createAnchorElement(String href, String suggestedName) { - final element = AnchorElement(href: href); - - if (suggestedName == null) { - element.download = 'download'; - } else { - element.download = suggestedName; - } - - return element; -} - -/// Add an element to a container and click it -void addElementToContainerAndClick(Element container, Element element) { - // Add the element and click it - // All previous elements will be removed before adding the new one - container.children.add(element); - element.click(); -} - -/// Initializes a DOM container where we can host elements. -Element ensureInitialized(String id) { - var target = querySelector('#${id}'); - if (target == null) { - final Element targetElement = Element.tag('flt-x-file')..id = id; - - querySelector('body')!.children.add(targetElement); - target = targetElement; - } - return target; -} diff --git a/packages/cross_file/lib/src/x_file.dart b/packages/cross_file/lib/src/x_file.dart deleted file mode 100644 index 6136bff39f36..000000000000 --- a/packages/cross_file/lib/src/x_file.dart +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -export 'types/interface.dart' - if (dart.library.html) 'types/html.dart' - if (dart.library.io) 'types/io.dart'; diff --git a/packages/cross_file/pubspec.yaml b/packages/cross_file/pubspec.yaml deleted file mode 100644 index 66d3f46a84e3..000000000000 --- a/packages/cross_file/pubspec.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: cross_file -description: An abstraction to allow working with files across multiple platforms. -homepage: https://github.com/flutter/plugins/tree/master/packages/cross_file -version: 0.3.1 - -dependencies: - flutter: - sdk: flutter - meta: ^1.3.0 - -dev_dependencies: - flutter_test: - sdk: flutter - pedantic: ^1.10.0 - -environment: - sdk: ">=2.12.0-259.9.beta <3.0.0" - flutter: ">=1.22.0" diff --git a/packages/cross_file/test/assets/hello.txt b/packages/cross_file/test/assets/hello.txt deleted file mode 100644 index 5dd01c177f5d..000000000000 --- a/packages/cross_file/test/assets/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello, world! \ No newline at end of file diff --git a/packages/cross_file/test/x_file_html_test.dart b/packages/cross_file/test/x_file_html_test.dart deleted file mode 100644 index a271aa1f1525..000000000000 --- a/packages/cross_file/test/x_file_html_test.dart +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2020 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -@TestOn('chrome') // Uses web-only Flutter SDK - -import 'dart:convert'; -import 'dart:html' as html; -import 'dart:typed_data'; - -import 'package:flutter_test/flutter_test.dart'; -import 'package:cross_file/cross_file.dart'; - -final String expectedStringContents = 'Hello, world!'; -final Uint8List bytes = Uint8List.fromList(utf8.encode(expectedStringContents)); -final html.File textFile = html.File([bytes], 'hello.txt'); -final String textFileUrl = html.Url.createObjectUrl(textFile); - -void main() { - group('Create with an objectUrl', () { - final file = XFile(textFileUrl); - - test('Can be read as a string', () async { - expect(await file.readAsString(), equals(expectedStringContents)); - }); - test('Can be read as bytes', () async { - expect(await file.readAsBytes(), equals(bytes)); - }); - - test('Can be read as a stream', () async { - expect(await file.openRead().first, equals(bytes)); - }); - - test('Stream can be sliced', () async { - expect(await file.openRead(2, 5).first, equals(bytes.sublist(2, 5))); - }); - }); - - group('Create from data', () { - final file = XFile.fromData(bytes); - - test('Can be read as a string', () async { - expect(await file.readAsString(), equals(expectedStringContents)); - }); - test('Can be read as bytes', () async { - expect(await file.readAsBytes(), equals(bytes)); - }); - - test('Can be read as a stream', () async { - expect(await file.openRead().first, equals(bytes)); - }); - - test('Stream can be sliced', () async { - expect(await file.openRead(2, 5).first, equals(bytes.sublist(2, 5))); - }); - }); - - group('saveTo(..)', () { - final String CrossFileDomElementId = '__x_file_dom_element'; - - group('CrossFile saveTo(..)', () { - test('creates a DOM container', () async { - XFile file = XFile.fromData(bytes); - - await file.saveTo(''); - - final container = html.querySelector('#${CrossFileDomElementId}'); - - expect(container, isNotNull); - }); - - test('create anchor element', () async { - XFile file = XFile.fromData(bytes, name: textFile.name); - - await file.saveTo('path'); - - final container = html.querySelector('#${CrossFileDomElementId}'); - final html.AnchorElement element = - container?.children.firstWhere((element) => element.tagName == 'A') - as html.AnchorElement; - - // if element is not found, the `firstWhere` call will throw StateError. - expect(element.href, file.path); - expect(element.download, file.name); - }); - - test('anchor element is clicked', () async { - final mockAnchor = html.AnchorElement(); - - CrossFileTestOverrides overrides = CrossFileTestOverrides( - createAnchorElement: (_, __) => mockAnchor, - ); - - XFile file = - XFile.fromData(bytes, name: textFile.name, overrides: overrides); - - bool clicked = false; - mockAnchor.onClick.listen((event) => clicked = true); - - await file.saveTo('path'); - - expect(clicked, true); - }); - }); - }); -} diff --git a/packages/cross_file/test/x_file_io_test.dart b/packages/cross_file/test/x_file_io_test.dart deleted file mode 100644 index 94ac81c4cac4..000000000000 --- a/packages/cross_file/test/x_file_io_test.dart +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2020 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -@TestOn('vm') // Uses dart:io - -import 'dart:convert'; -import 'dart:io'; -import 'dart:typed_data'; - -import 'package:flutter_test/flutter_test.dart'; -import 'package:cross_file/cross_file.dart'; - -final pathPrefix = - Directory.current.path.endsWith('test') ? './assets/' : './test/assets/'; -final path = pathPrefix + 'hello.txt'; -final String expectedStringContents = 'Hello, world!'; -final Uint8List bytes = Uint8List.fromList(utf8.encode(expectedStringContents)); -final File textFile = File(path); -final String textFilePath = textFile.path; - -void main() { - group('Create with a path', () { - final XFile file = XFile(textFilePath); - - test('Can be read as a string', () async { - expect(await file.readAsString(), equals(expectedStringContents)); - }); - test('Can be read as bytes', () async { - expect(await file.readAsBytes(), equals(bytes)); - }); - - test('Can be read as a stream', () async { - expect(await file.openRead().first, equals(bytes)); - }); - - test('Stream can be sliced', () async { - expect(await file.openRead(2, 5).first, equals(bytes.sublist(2, 5))); - }); - - test('saveTo(..) creates file', () async { - File removeBeforeTest = File(pathPrefix + 'newFilePath.txt'); - if (removeBeforeTest.existsSync()) { - await removeBeforeTest.delete(); - } - - await file.saveTo(pathPrefix + 'newFilePath.txt'); - File newFile = File(pathPrefix + 'newFilePath.txt'); - - expect(newFile.existsSync(), isTrue); - expect(newFile.readAsStringSync(), 'Hello, world!'); - - await newFile.delete(); - }); - }); - - group('Create with data', () { - final file = XFile.fromData(bytes); - - test('Can be read as a string', () async { - expect(await file.readAsString(), equals(expectedStringContents)); - }); - test('Can be read as bytes', () async { - expect(await file.readAsBytes(), equals(bytes)); - }); - - test('Can be read as a stream', () async { - expect(await file.openRead().first, equals(bytes)); - }); - - test('Stream can be sliced', () async { - expect(await file.openRead(2, 5).first, equals(bytes.sublist(2, 5))); - }); - - test('Function saveTo(..) creates file', () async { - File removeBeforeTest = File(pathPrefix + 'newFileData.txt'); - if (removeBeforeTest.existsSync()) { - await removeBeforeTest.delete(); - } - - await file.saveTo(pathPrefix + 'newFileData.txt'); - File newFile = File(pathPrefix + 'newFileData.txt'); - - expect(newFile.existsSync(), isTrue); - expect(newFile.readAsStringSync(), 'Hello, world!'); - - await newFile.delete(); - }); - }); -}