Skip to content

Commit

Permalink
Use md5 hash for etag in mem_storage (#8111)
Browse files Browse the repository at this point in the history
  • Loading branch information
szakarias authored Oct 7, 2024
1 parent d2af649 commit 67ccc86
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/fake_gcloud/lib/mem_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';

import 'package:_discoveryapis_commons/_discoveryapis_commons.dart';
import 'package:crypto/crypto.dart';
import 'package:gcloud/storage.dart';
import 'package:logging/logging.dart';

Expand Down Expand Up @@ -130,6 +131,8 @@ class _File implements ObjectInfo {
@override
final int crc32CChecksum;
@override
final List<int> md5Hash;
@override
final DateTime updated;
@override
final ObjectMetadata metadata;
Expand All @@ -141,14 +144,15 @@ class _File implements ObjectInfo {
DateTime? updated,
}) : // TODO: use a real CRC32 check
crc32CChecksum = content.fold<int>(0, (a, b) => a + b) & 0xffffffff,
md5Hash = md5.convert(content).bytes,
updated = updated ?? DateTime.now().toUtc(),
metadata = ObjectMetadata(acl: Acl([]));

@override
Uri get downloadLink => Uri(scheme: 'gs', host: bucketName, path: name);

@override
String get etag => crc32CChecksum.toRadixString(16);
String get etag => md5Hash.toString();

@override
ObjectGeneration get generation {
Expand All @@ -158,9 +162,6 @@ class _File implements ObjectInfo {

@override
int get length => content.length;

@override
List<int> get md5Hash => etag.codeUnits;
}

class _Bucket implements Bucket {
Expand Down

0 comments on commit 67ccc86

Please sign in to comment.