web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

  1. # jest-serializer
  2. Module for serializing and deserializing object into memory and disk. By default, the `v8` implementations are used, but if not present, it defaults to `JSON` implementation. Both serializers have the advantage of being able to serialize `Map`, `Set`, `undefined`, `NaN`, etc, although the JSON one does it through a replacer/reviver.
  3. ## Install
  4. ```sh
  5. $ yarn add jest-serializer
  6. ```
  7. ## API
  8. Three kinds of API groups are exposed:
  9. ### In-memory serialization: `serialize` and `deserialize`
  10. This set of functions take or return a `Buffer`. All the process happens in memory. This is useful when willing to transfer over HTTP, TCP or via UNIX pipes.
  11. ```javascript
  12. import {deserialize, serialize} from 'jest-serializer';
  13. const myObject = {
  14. foo: 'bar',
  15. baz: [0, true, '2', [], {}],
  16. };
  17. const buffer = serialize(myObject);
  18. const myCopyObject = deserialize(buffer);
  19. ```
  20. ### Synchronous persistent filesystem: `readFileSync` and `writeFileSync`
  21. This set of functions allow to send to disk a serialization result and retrieve it back, in a synchronous way. It mimics the `fs` API so it looks familiar.
  22. ```javascript
  23. import {readFileSync, writeFileSync} from 'jest-serializer';
  24. const myObject = {
  25. foo: 'bar',
  26. baz: [0, true, '2', [], {}],
  27. };
  28. const myFile = '/tmp/obj';
  29. writeFileSync(myFile, myObject);
  30. const myCopyObject = readFileSync(myFile);
  31. ```