Home Reference Source Repository

js/Foundation/NSKeyedArchiver.js

  1. 'use strict'
  2.  
  3. import NSCoder from './NSCoder'
  4. //import NSMutableData from './NSMutableData'
  5. //import NSKeyedArchiverDelegate from '../undefined/NSKeyedArchiverDelegate'
  6.  
  7.  
  8. /**
  9. * NSKeyedArchiver, a concrete subclass of NSCoder, provides a way to encode objects (and scalar values) into an architecture-independent format that can be stored in a file. When you archive a set of objects, the class information and instance variables for each object are written to the archive. NSKeyedArchiver’s companion class, NSKeyedUnarchiver, decodes the data in an archive and creates a set of objects equivalent to the original set.
  10. * @access public
  11. * @extends {NSCoder}
  12. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver
  13. */
  14. export default class NSKeyedArchiver extends NSCoder {
  15. // Initializers
  16.  
  17. /**
  18. *
  19. * @access public
  20. * @constructor
  21. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1642790-init
  22. */
  23. constructor() {
  24. super()
  25.  
  26. // Archiving Data
  27.  
  28. /**
  29. * The format in which the receiver encodes its data.
  30. * @type {PropertyListSerialization.PropertyListFormat}
  31. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1417520-outputformat
  32. */
  33. this.outputFormat = null
  34.  
  35. /**
  36. * Indicates whether the receiver requires all archived classes to conform to NSSecureCoding.
  37. * @type {boolean}
  38. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1417084-requiressecurecoding
  39. */
  40. this.requiresSecureCoding = false
  41.  
  42.  
  43. // Managing the Delegate
  44.  
  45. /**
  46. * The archiver’s delegate.
  47. * @type {?NSKeyedArchiverDelegate}
  48. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1412809-delegate
  49. */
  50. this.delegate = null
  51.  
  52.  
  53. // Instance Properties
  54.  
  55. this._encodedData = null
  56. }
  57.  
  58. // Initializing an NSKeyedArchiver Object
  59.  
  60. /**
  61. * Returns the receiver, initialized for encoding an archive into a given a mutable-data object.
  62. * @access public
  63. * @param {NSMutableData} data - The mutable-data object into which the archive is written.
  64. * @returns {NSKeyedArchiver}
  65. * @desc When you finish encoding data, you must invoke finishEncoding() at which point data is filled. The format of the receiver is NSPropertyListBinaryFormat_v1_0.
  66. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1409579-init
  67. */
  68. //initForWritingWith(data) {
  69. static archiverForWritingWithData(data) {
  70. const instance = new NSKeyedArchiver()
  71.  
  72. // TODO: implement
  73.  
  74. return instance
  75. }
  76.  
  77. // Archiving Data
  78.  
  79. /**
  80. * Returns an NSData object containing the encoded form of the object graph whose root object is given.
  81. * @access public
  82. * @param {Object} rootObject -
  83. * @returns {Data} -
  84. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1413189-archiveddata
  85. */
  86. static archivedDataWithRootObject(rootObject) {
  87. return null
  88. }
  89.  
  90. /**
  91. * Archives an object graph rooted at a given object by encoding it into a data object then atomically writes the resulting data object to a file at a given path, and returns a Boolean value that indicates whether the operation was successful.
  92. * @access public
  93. * @param {Object} rootObject -
  94. * @param {string} path - The path of the file in which to write the archive.
  95. * @returns {boolean} -
  96. * @desc The format of the archive is NSPropertyListBinaryFormat_v1_0.
  97. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1410621-archiverootobject
  98. */
  99. static archiveRootObjectToFile(rootObject, path) {
  100. return false
  101. }
  102.  
  103. /**
  104. * Instructs the receiver to construct the final data stream.
  105. * @access public
  106. * @returns {void}
  107. * @desc No more values can be encoded after this method is called. You must call this method when finished.
  108. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1413904-finishencoding
  109. */
  110. finishEncoding() {
  111. }
  112.  
  113. // Encoding Data and Objects
  114.  
  115. /**
  116. * Encodes a given float value and associates it with a given key.
  117. * @access public
  118. * @param {number} realv - The value to encode.
  119. * @param {string} key - The key with which to associate realv. This value must not be nil.
  120. * @returns {void}
  121. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1416972-encode
  122. */
  123. encodeForKey(realv, key) {
  124. }
  125.  
  126. /**
  127. * Encodes a given number of bytes from a given C array of bytes and associates them with the a given key.
  128. * @access public
  129. * @param {?UnsafePointer<UInt8>} bytesp - A C array of bytes to encode.
  130. * @param {number} lenv - The number of bytes from bytesp to encode.
  131. * @param {string} key - The key with which to associate the encoded value. This value must not be nil.
  132. * @returns {void}
  133. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1417696-encodebytes
  134. */
  135. encodeBytesLengthForKey(bytesp, lenv, key) {
  136. }
  137.  
  138. /**
  139. * Encodes a reference to a given object and associates it with a given key only if it has been unconditionally encoded elsewhere in the archive with encode(_:forKey:).
  140. * @access public
  141. * @param {?Object} objv - The object to encode.
  142. * @param {string} key - The key with which to associate the encoded value. This value must not be nil.
  143. * @returns {void}
  144. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1413677-encodeconditionalobject
  145. */
  146. encodeConditionalObjectForKey(objv, key) {
  147. }
  148.  
  149. // Managing Classes and Class Names
  150.  
  151. /**
  152. * Adds a class translation mapping to the receiver whereby instances of of a given class are encoded with a given class name instead of their real class names.
  153. * @access public
  154. * @param {?string} codedName -
  155. * @param {Object} cls - The class for which to set up a translation mapping.
  156. * @returns {void}
  157. * @desc When encoding, the receiver’s translation map overrides any translation that may also be present in the class’s map.
  158. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1414746-setclassname
  159. */
  160. static setClassNameFor(codedName, cls) {
  161. }
  162.  
  163. /**
  164. * Returns the class name with which the receiver encodes instances of a given class.
  165. * @access public
  166. * @param {Object} cls - The class for which to determine the translation mapping.
  167. * @returns {?string} -
  168. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1407245-classname
  169. */
  170. static classNameFor(cls) {
  171. return null
  172. }
  173.  
  174. // Instance Properties
  175. /**
  176. * Returns the encoded data for the archiver.
  177. * @type {Data}
  178. * @desc If encoding has not yet finished, invoking this property calls finishEncoding() and returns the data. If you initialized the keyed archiver with a specific mutable data instance, then that data is returned by the property after finishEncoding() is called.
  179. * @see https://developer.apple.com/documentation/foundation/nskeyedarchiver/1643042-encodeddata
  180. */
  181. get encodedData() {
  182. return this._encodedData
  183. }
  184. }