Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit f9c7f89

Browse files
authored
docs: Document CRC32CValidator (#2006)
* docs: Document `CRC32CValidator` in `Storage` * fix: `@private` value warning * docs: Update parameter names * docs: `CRC32CValidator` documentation
1 parent 9b1c4b3 commit f9c7f89

4 files changed

Lines changed: 193 additions & 5 deletions

File tree

src/bucket.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,70 @@ export enum BucketExceptionMessages {
391391
SUPPLY_NOTIFICATION_ID = 'You must supply a notification ID.',
392392
}
393393

394+
/**
395+
* @callback Crc32cGeneratorToStringCallback
396+
* A method returning the CRC32C as a base64-encoded string.
397+
*
398+
* @returns {string}
399+
*
400+
* @example
401+
* Hashing the string 'data' should return 'rth90Q=='
402+
*
403+
* ```js
404+
* const buffer = Buffer.from('data');
405+
* crc32c.update(buffer);
406+
* crc32c.toString(); // 'rth90Q=='
407+
* ```
408+
**/
409+
/**
410+
* @callback Crc32cGeneratorValidateCallback
411+
* A method validating a base64-encoded CRC32C string.
412+
*
413+
* @param {string} [value] base64-encoded CRC32C string to validate
414+
* @returns {boolean}
415+
*
416+
* @example
417+
* Should return `true` if the value matches, `false` otherwise
418+
*
419+
* ```js
420+
* const buffer = Buffer.from('data');
421+
* crc32c.update(buffer);
422+
* crc32c.validate('DkjKuA=='); // false
423+
* crc32c.validate('rth90Q=='); // true
424+
* ```
425+
**/
426+
/**
427+
* @callback Crc32cGeneratorUpdateCallback
428+
* A method for passing `Buffer`s for CRC32C generation.
429+
*
430+
* @param {Buffer} [data] data to update CRC32C value with
431+
* @returns {undefined}
432+
*
433+
* @example
434+
* Hashing buffers from 'some ' and 'text\n'
435+
*
436+
* ```js
437+
* const buffer1 = Buffer.from('some ');
438+
* crc32c.update(buffer1);
439+
*
440+
* const buffer2 = Buffer.from('text\n');
441+
* crc32c.update(buffer2);
442+
*
443+
* crc32c.toString(); // 'DkjKuA=='
444+
* ```
445+
**/
446+
/**
447+
* @typedef {object} CRC32CValidator
448+
* @property {Crc32cGeneratorToStringCallback}
449+
* @property {Crc32cGeneratorValidateCallback}
450+
* @property {Crc32cGeneratorUpdateCallback}
451+
*/
452+
/**
453+
* A function that generates a CRC32C Validator. Defaults to {@link CRC32C}
454+
*
455+
* @name Bucket#crc32cGenerator
456+
* @type {CRC32CValidator}
457+
*/
394458
/**
395459
* Get and set IAM policies for your bucket.
396460
*
@@ -708,7 +772,7 @@ class Bucket extends ServiceObject {
708772
},
709773
},
710774
/**
711-
* @typedef {object} DeleteBucketOptions Configuration options.
775+
* IamDeleteBucketOptions Configuration options.
712776
* @property {boolean} [ignoreNotFound = false] Ignore an error if
713777
* the bucket does not exist.
714778
* @property {string} [userProject] The ID of the project which will be

src/crc32c.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ interface CRC32CValidator {
9191
* crc32c.validate('rth90Q=='); // true
9292
* ```
9393
*/
94-
validate: (o: string) => boolean;
94+
validate: (value: string) => boolean;
9595
/**
9696
* A method for passing `Buffer`s for CRC32C generation.
9797
*
@@ -108,7 +108,7 @@ interface CRC32CValidator {
108108
* crc32c.toString(); // 'DkjKuA=='
109109
* ```
110110
*/
111-
update: (b: Buffer) => void;
111+
update: (data: Buffer) => void;
112112
}
113113

114114
/** A function that generates a CRC32C Validator */

src/file.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,11 @@ export enum ActionToHTTPMethod {
278278
}
279279

280280
/**
281-
* @const {string}
282281
* @private
283282
*/
284283
export const STORAGE_POST_POLICY_BASE_URL = 'https://storage.googleapis.com';
285284

286285
/**
287-
* @const {RegExp}
288286
* @private
289287
*/
290288
const GS_URL_REGEXP = /^gs:\/\/([a-z0-9_.-]+)\/(.+)$/;
@@ -500,6 +498,68 @@ class File extends ServiceObject<File> {
500498
* @name File#name
501499
* @type {string}
502500
*/
501+
/**
502+
* @callback Crc32cGeneratorToStringCallback
503+
* A method returning the CRC32C as a base64-encoded string.
504+
*
505+
* @returns {string}
506+
*
507+
* @example
508+
* Hashing the string 'data' should return 'rth90Q=='
509+
*
510+
* ```js
511+
* const buffer = Buffer.from('data');
512+
* crc32c.update(buffer);
513+
* crc32c.toString(); // 'rth90Q=='
514+
* ```
515+
**/
516+
/**
517+
* @callback Crc32cGeneratorValidateCallback
518+
* A method validating a base64-encoded CRC32C string.
519+
*
520+
* @param {string} [value] base64-encoded CRC32C string to validate
521+
* @returns {boolean}
522+
*
523+
* @example
524+
* Should return `true` if the value matches, `false` otherwise
525+
*
526+
* ```js
527+
* const buffer = Buffer.from('data');
528+
* crc32c.update(buffer);
529+
* crc32c.validate('DkjKuA=='); // false
530+
* crc32c.validate('rth90Q=='); // true
531+
* ```
532+
**/
533+
/**
534+
* @callback Crc32cGeneratorUpdateCallback
535+
* A method for passing `Buffer`s for CRC32C generation.
536+
*
537+
* @param {Buffer} [data] data to update CRC32C value with
538+
* @returns {undefined}
539+
*
540+
* @example
541+
* Hashing buffers from 'some ' and 'text\n'
542+
*
543+
* ```js
544+
* const buffer1 = Buffer.from('some ');
545+
* crc32c.update(buffer1);
546+
*
547+
* const buffer2 = Buffer.from('text\n');
548+
* crc32c.update(buffer2);
549+
*
550+
* crc32c.toString(); // 'DkjKuA=='
551+
* ```
552+
**/
553+
/**
554+
* @typedef {object} CRC32CValidator
555+
* @property {Crc32cGeneratorToStringCallback}
556+
* @property {Crc32cGeneratorValidateCallback}
557+
* @property {Crc32cGeneratorUpdateCallback}
558+
*/
559+
/**
560+
* @callback Crc32cGeneratorCallback
561+
* @returns {CRC32CValidator}
562+
*/
503563
/**
504564
* @typedef {object} FileOptions Options passed to the File constructor.
505565
* @property {string} [encryptionKey] A custom encryption key.
@@ -509,6 +569,7 @@ class File extends ServiceObject<File> {
509569
* usable only by enabled projects.
510570
* @property {string} [userProject] The ID of the project which will be
511571
* billed for all requests made from File object.
572+
* @property {Crc32cGeneratorCallback} [callback] A function that generates a CRC32C Validator. Defaults to {@link CRC32C}
512573
*/
513574
/**
514575
* Constructs a file object.

src/storage.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,68 @@ export class Storage extends Service {
486486

487487
retryOptions: RetryOptions;
488488

489+
/**
490+
* @callback Crc32cGeneratorToStringCallback
491+
* A method returning the CRC32C as a base64-encoded string.
492+
*
493+
* @returns {string}
494+
*
495+
* @example
496+
* Hashing the string 'data' should return 'rth90Q=='
497+
*
498+
* ```js
499+
* const buffer = Buffer.from('data');
500+
* crc32c.update(buffer);
501+
* crc32c.toString(); // 'rth90Q=='
502+
* ```
503+
**/
504+
/**
505+
* @callback Crc32cGeneratorValidateCallback
506+
* A method validating a base64-encoded CRC32C string.
507+
*
508+
* @param {string} [value] base64-encoded CRC32C string to validate
509+
* @returns {boolean}
510+
*
511+
* @example
512+
* Should return `true` if the value matches, `false` otherwise
513+
*
514+
* ```js
515+
* const buffer = Buffer.from('data');
516+
* crc32c.update(buffer);
517+
* crc32c.validate('DkjKuA=='); // false
518+
* crc32c.validate('rth90Q=='); // true
519+
* ```
520+
**/
521+
/**
522+
* @callback Crc32cGeneratorUpdateCallback
523+
* A method for passing `Buffer`s for CRC32C generation.
524+
*
525+
* @param {Buffer} [data] data to update CRC32C value with
526+
* @returns {undefined}
527+
*
528+
* @example
529+
* Hashing buffers from 'some ' and 'text\n'
530+
*
531+
* ```js
532+
* const buffer1 = Buffer.from('some ');
533+
* crc32c.update(buffer1);
534+
*
535+
* const buffer2 = Buffer.from('text\n');
536+
* crc32c.update(buffer2);
537+
*
538+
* crc32c.toString(); // 'DkjKuA=='
539+
* ```
540+
**/
541+
/**
542+
* @typedef {object} CRC32CValidator
543+
* @property {Crc32cGeneratorToStringCallback}
544+
* @property {Crc32cGeneratorValidateCallback}
545+
* @property {Crc32cGeneratorUpdateCallback}
546+
*/
547+
/**
548+
* @callback Crc32cGeneratorCallback
549+
* @returns {CRC32CValidator}
550+
*/
489551
/**
490552
* @typedef {object} StorageOptions
491553
* @property {string} [projectId] The project ID from the Google Developer's
@@ -536,6 +598,7 @@ export class Storage extends Service {
536598
* @property {object[]} [interceptors_] Array of custom request interceptors to be returned in the order they were assigned.
537599
* @property {string} [apiEndpoint = storage.google.com] The API endpoint of the service used to make requests.
538600
* @property {boolean} [useAuthWithCustomEndpoint = false] Controls whether or not to use authentication when using a custom endpoint.
601+
* @property {Crc32cGeneratorCallback} [callback] A function that generates a CRC32C Validator. Defaults to {@link CRC32C}
539602
*/
540603
/**
541604
* Constructs the Storage client.

0 commit comments

Comments
 (0)