Porting code to Pharo 2.0
Asked Answered
I

3

9

Pharo 2.0 changed some basic API bits, and I cannot found the new way of doing the following:

  1. FileDirectory default directoryNamed: aFolderString.
  2. FileDirectory on: aFilename.
  3. FileDirectory default assureExistenceOfPath: aString.
  4. ReferenceStream on: stream.

What would be the new equivalent code? Is there an update guide available describing how to translate or port code?

Implicate answered 2/4, 2013 at 6:26 Comment(0)
B
9

I have collected some translations you may find useful:

+------------------------------------------------------+---------------------------------------------------------------------------+
|                    FileDirectory                     |                                FileSystem                                 |
+------------------------------------------------------+---------------------------------------------------------------------------+
| FileDirectory assureExistence.                       | aString asFileReference ensureDirectory.                                  |
| FileDirectory baseNameFor: aString.                  | aString asFileReference base.                                             |
| FileDirectory containingDirectory.                   | Path parent asFileReference pathString.                                   |
| FileDirectory default deleteFileNamed: aString.      | aString asFileReference ensureDeleted.                                    |
| FileDirectory default directoryExists: aString.      | aString asFileReference exists.                                           |
| FileDirectory default directoryNamed: aFolderString. | FileSystem disk / aFolderString.                                          |
| FileDirectory directoryEntryFor: aString.            | aString asFilereference.                                                  |
| (FileDirectory entryFor: aString) / 'filename'.      | aString asFileReference / 'filename'.                                     |
| FileDirectory extensionFor: aString.                 | aString asFileReference extension.                                        |
| FileDirectory default fileExists: aString.           | aString asFileReference exists. " or " DiskStore current isFile: aString. |
| FileDirectory default fullNameFor: aString.          | aString asFileReference fullName.                                                         |
| FileDirectory default pathName.                      | FileSystem disk workingDirectory fullName.                                |
| FileDirectory on: aFilename.                         | aFilename asFileReference.                                                |
| (FileDirectory on: aString) entries collect: #name.  | aString asFileReference children collect: #basename.                      |
| (FileDirectory on: aString) entryAt: 'filename'.     | aString asFileReference / 'filename'.                                     |
| FileDirectory oldFileNamed: aString.                 | aString asFileReference readStream.                                       |
| FileDirectory slash.                                 | FileSystem disk separator. " or " DiskStore delimiter asString.           |
+------------------------------------------------------+---------------------------------------------------------------------------+
Bulbous answered 23/4, 2013 at 0:28 Comment(0)
S
13

The following statements correspond do the ones you put in your question.

  1. FileSystem workingDirectory / aFolderString
  2. aFilename asFileReference
  3. aString asFileReference ensureDirectory
  4. ReferenceStream does no longer exist in 2.0.

aPathString asFileReference resolves aPathString, so if there are slashes in your name you will end up in a subdirectory.

/ on the other hand takes a single directory or file name as an argument, and does not resolve further subdirectories. Depending on your platform you can easily refer to a file named foo/bar with a slash in the name with FileSystem workingDirectory / 'foo/bar'.

School answered 2/4, 2013 at 7:13 Comment(0)
B
9

I have collected some translations you may find useful:

+------------------------------------------------------+---------------------------------------------------------------------------+
|                    FileDirectory                     |                                FileSystem                                 |
+------------------------------------------------------+---------------------------------------------------------------------------+
| FileDirectory assureExistence.                       | aString asFileReference ensureDirectory.                                  |
| FileDirectory baseNameFor: aString.                  | aString asFileReference base.                                             |
| FileDirectory containingDirectory.                   | Path parent asFileReference pathString.                                   |
| FileDirectory default deleteFileNamed: aString.      | aString asFileReference ensureDeleted.                                    |
| FileDirectory default directoryExists: aString.      | aString asFileReference exists.                                           |
| FileDirectory default directoryNamed: aFolderString. | FileSystem disk / aFolderString.                                          |
| FileDirectory directoryEntryFor: aString.            | aString asFilereference.                                                  |
| (FileDirectory entryFor: aString) / 'filename'.      | aString asFileReference / 'filename'.                                     |
| FileDirectory extensionFor: aString.                 | aString asFileReference extension.                                        |
| FileDirectory default fileExists: aString.           | aString asFileReference exists. " or " DiskStore current isFile: aString. |
| FileDirectory default fullNameFor: aString.          | aString asFileReference fullName.                                                         |
| FileDirectory default pathName.                      | FileSystem disk workingDirectory fullName.                                |
| FileDirectory on: aFilename.                         | aFilename asFileReference.                                                |
| (FileDirectory on: aString) entries collect: #name.  | aString asFileReference children collect: #basename.                      |
| (FileDirectory on: aString) entryAt: 'filename'.     | aString asFileReference / 'filename'.                                     |
| FileDirectory oldFileNamed: aString.                 | aString asFileReference readStream.                                       |
| FileDirectory slash.                                 | FileSystem disk separator. " or " DiskStore delimiter asString.           |
+------------------------------------------------------+---------------------------------------------------------------------------+
Bulbous answered 23/4, 2013 at 0:28 Comment(0)
S
5

ReferenceStream is not supported anymore and has been deleted in Pharo 2.0. You should use Fuel which is well written, well documented, well tested and very fast. http://rmod.lille.inria.fr/web/pier/software/Fuel

Scoville answered 2/4, 2013 at 8:57 Comment(2)
I don't mean to troll you but your answer is not answering the question (it's appropriate as comment to the question though)Erethism
Besides if you use Fuel to materialize a ReferenceStream, you will get a FLBadSignature exceptionBerkey

© 2022 - 2024 — McMap. All rights reserved.