-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ 0.9.0 Release ] Add support for uploading images through SubredditS…
…tyleSheet (#167)
- Loading branch information
Showing
24 changed files
with
286 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/// Copyright (c) 2019, the Dart Reddit API Wrapper project authors. | ||
/// Please see the AUTHORS file for details. All rights reserved. | ||
/// Use of this source code is governed by a BSD-style license that | ||
/// can be found in the LICENSE file. | ||
export 'image_file_reader_unsupported.dart' | ||
if (dart.library.io) 'image_file_reader_io.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// Copyright (c) 2019, the Dart Reddit API Wrapper project authors. | ||
/// Please see the AUTHORS file for details. 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:io'; | ||
import 'package:draw/src/models/subreddit.dart'; | ||
import 'package:collection/collection.dart'; | ||
|
||
const String _kJpegHeader = '\xff\xd8\xff'; | ||
|
||
Future<Map> loadImage(Uri imagePath) async { | ||
final image = File.fromUri(imagePath); | ||
if (!await image.exists()) { | ||
throw FileSystemException('File does not exist', imagePath.toString()); | ||
} | ||
final imageBytes = await image.readAsBytes(); | ||
if (imageBytes.length < _kJpegHeader.length) { | ||
throw FormatException('Invalid image format for file $imagePath.'); | ||
} | ||
final header = imageBytes.sublist(0, _kJpegHeader.length); | ||
final isJpeg = | ||
const IterableEquality().equals(_kJpegHeader.codeUnits, header); | ||
return { | ||
'imageBytes': imageBytes, | ||
'imageType': isJpeg ? ImageFormat.jpeg : ImageFormat.png, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/// Copyright (c) 2019, the Dart Reddit API Wrapper project authors. | ||
/// Please see the AUTHORS file for details. All rights reserved. | ||
/// Use of this source code is governed by a BSD-style license that | ||
/// can be found in the LICENSE file. | ||
Future<Map> loadImage(Uri imagePath) async => | ||
throw UnsupportedError('Loading images from disk is not supported on web.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.