BREAKING(io/unstable): remove sliceLongToBytes() (#6005)

This commit is contained in:
Asher Gomez 2024-09-25 13:58:16 +10:00 committed by GitHub
parent 548d254f31
commit eb064eba09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 0 additions and 58 deletions

View File

@ -18,7 +18,6 @@
"./read-short": "./read_short.ts",
"./read-string-delim": "./read_string_delim.ts",
"./reader-from-stream-reader": "./reader_from_stream_reader.ts",
"./slice-long-to-bytes": "./slice_long_to_bytes.ts",
"./string-reader": "./string_reader.ts",
"./string-writer": "./string_writer.ts",
"./to-readable-stream": "./to_readable_stream.ts",

View File

@ -31,7 +31,6 @@ export * from "./read_range.ts";
export * from "./read_short.ts";
export * from "./read_string_delim.ts";
export * from "./reader_from_stream_reader.ts";
export * from "./slice_long_to_bytes.ts";
export * from "./string_reader.ts";
export * from "./string_writer.ts";
export * from "./to_readable_stream.ts";

View File

@ -1,32 +0,0 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/**
* Slice number into 64bit big endian byte array.
*
* @example Usage
* ```ts
* import { sliceLongToBytes } from "@std/io/slice-long-to-bytes";
* import { assertEquals } from "@std/assert/equals";
*
* const dest = sliceLongToBytes(0x123456789a);
* assertEquals(dest, [0, 0, 0, 0x12, 0x34, 0x56, 0x78, 0x9a]);
* ```
*
* @param d The number to be sliced
* @param dest The array to store the sliced bytes
* @returns The sliced bytes
*
* @deprecated This will be removed in 0.225.0.
*/
export function sliceLongToBytes(
d: number,
dest: number[] = Array.from<number>({ length: 8 }),
): number[] {
let big = BigInt(d);
for (let i = 0; i < 8; i++) {
dest[7 - i] = Number(big & 0xffn);
big >>= 8n;
}
return dest;
}

View File

@ -1,24 +0,0 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { readLong } from "./read_long.ts";
import { sliceLongToBytes } from "./slice_long_to_bytes.ts";
import { BufReader } from "./buf_reader.ts";
import { BinaryReader } from "./_test_common.ts";
Deno.test("testSliceLongToBytes", function () {
const arr = sliceLongToBytes(0x1234567890abcdef);
const actual = readLong(new BufReader(new BinaryReader(new Uint8Array(arr))));
const expected = readLong(
new BufReader(
new BinaryReader(
new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef]),
),
),
);
assertEquals(actual, expected);
});
Deno.test("testSliceLongToBytes2", function () {
const arr = sliceLongToBytes(0x12345678);
assertEquals(arr, [0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]);
});