Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename calculateSha256 functions #790

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/client-s3/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { calculateSha256 as streamHasher } from "@aws-sdk/hash-blob-browser";
import { blobHasher as streamHasher } from "@aws-sdk/hash-blob-browser";
import { invalidFunction } from "@aws-sdk/invalid-dependency";
import { Md5 } from "@aws-sdk/md5-js";
import { Sha256 } from "@aws-crypto/sha256-browser";
Expand Down
2 changes: 1 addition & 1 deletion clients/client-s3/runtimeConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
import { calculateSha256 as streamHasher } from "@aws-sdk/hash-stream-node";
import { fileStreamHasher as streamHasher } from "@aws-sdk/hash-stream-node";
import { defaultProvider as regionDefaultProvider } from "@aws-sdk/region-provider";
import { HashConstructor as __HashConstructor } from "@aws-sdk/types";
import { Hash } from "@aws-sdk/hash-node";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public void addRuntimeConfigValues(
switch (target) {
case NODE:
writer.addDependency(AwsDependency.STREAM_HASHER_NODE);
writer.addImport("calculateSha256", "streamHasher", AwsDependency.STREAM_HASHER_NODE.packageName);
writer.addImport("fileStreamHasher", "streamHasher", AwsDependency.STREAM_HASHER_NODE.packageName);
writer.write("streamHasher,");
break;
case BROWSER:
writer.addDependency(AwsDependency.STREAM_HASHER_BROWSER);
writer.addImport("calculateSha256", "streamHasher", AwsDependency.STREAM_HASHER_BROWSER.packageName);
writer.addImport("blobHasher", "streamHasher", AwsDependency.STREAM_HASHER_BROWSER.packageName);
writer.write("streamHasher,");
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions packages/hash-blob-browser/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Sha256 } from "@aws-crypto/sha256-js";
import { toHex } from "@aws-sdk/util-hex-encoding";
import { calculateSha256 } from "./index";
import { blobHasher } from "./index";

describe("calculateSha256", () => {
describe("blobHasher", () => {
const blob = new Blob([
"Shot through the bar, but you're too late bizzbuzz you give foo, a bad name."
]);

it("calculates the SHA256 hash of a blob", async () => {
const result = await calculateSha256(Sha256, blob);
const result = await blobHasher(Sha256, blob);

expect(result instanceof Uint8Array).toBe(true);
expect(toHex(result)).toBe(
Expand Down
2 changes: 1 addition & 1 deletion packages/hash-blob-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Hash, HashConstructor, StreamHasher } from "@aws-sdk/types";

import { blobReader } from "@aws-sdk/chunked-blob-reader";

export const calculateSha256: StreamHasher<Blob> = async function calculateSha256(
export const blobHasher: StreamHasher<Blob> = async function blobHasher(
hashCtor: HashConstructor,
blob: Blob
): Promise<Uint8Array> {
Expand Down
10 changes: 5 additions & 5 deletions packages/hash-stream-node/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tmpdir } from "os";
import { Readable } from "stream";
import { Sha256 } from "@aws-crypto/sha256-js";
import { toHex } from "@aws-sdk/util-hex-encoding";
import { calculateSha256 } from "./index";
import { fileStreamHasher } from "./index";

function createTemporaryFile(contents: string): string {
const folder = mkdtempSync(join(tmpdir(), "sha256-stream-node-"));
Expand All @@ -14,13 +14,13 @@ function createTemporaryFile(contents: string): string {
return fileLoc;
}

describe("calculateSha256", () => {
describe("fileStreamHasher", () => {
const temporaryFile = createTemporaryFile(
"Shot through the bar, but you're too late bizzbuzz you give foo, a bad name."
);

it("calculates the SHA256 hash of a stream", async () => {
const result = await calculateSha256(
const result = await fileStreamHasher(
Sha256,
createReadStream(temporaryFile)
);
Expand All @@ -37,7 +37,7 @@ describe("calculateSha256", () => {
const onSpy = jest.spyOn(inputStream, "on");
const pipeSpy = jest.spyOn(inputStream, "pipe");

const result = await calculateSha256(Sha256, inputStream);
const result = await fileStreamHasher(Sha256, inputStream);

expect(result instanceof Uint8Array).toBe(true);
expect(toHex(result)).toBe(
Expand All @@ -51,7 +51,7 @@ describe("calculateSha256", () => {
const inputStream = new Readable();

await expect(
calculateSha256(Sha256, inputStream as any)
fileStreamHasher(Sha256, inputStream as any)
).rejects.toHaveProperty("message");
});
});
2 changes: 1 addition & 1 deletion packages/hash-stream-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HashCalculator } from "./hash-calculator";
import { createReadStream, ReadStream } from "fs";
import { Readable } from "stream";

export const calculateSha256: StreamHasher<Readable> = function calculateSha256(
export const fileStreamHasher: StreamHasher<Readable> = function fileStreamHasher(
hashCtor: HashConstructor,
fileStream: Readable
): Promise<Uint8Array> {
Expand Down