mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
This changes how files work. There is now an open function that translates a path to a file handle (id). Then this handle is used to perform other actions on the file. The file contents are moved to a separate table so that the actual file storage is independent of the database (e.g. in the future, we may use File Access API). We store a hash of the file contents in the metadata file so we can detect file changes without having to compare file contents. We also separate the change and add actions.
12 lines
383 B
TypeScript
12 lines
383 B
TypeScript
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2022 The Pybricks Authors
|
|
|
|
const encoder = new TextEncoder();
|
|
|
|
export async function sha256Digest(data: string): Promise<string> {
|
|
const hash = await window.crypto.subtle.digest('SHA-256', encoder.encode(data));
|
|
return Array.from(new Uint8Array(hash))
|
|
.map((n) => n.toString(16).padStart(2, '0'))
|
|
.join('');
|
|
}
|